1 19 20 package org.netbeans.modules.project.ant.task; 21 22 import java.beans.PropertyVetoException ; 23 import java.io.File ; 24 import java.io.IOException ; 25 import org.apache.tools.ant.BuildException; 26 import org.apache.tools.ant.Task; 27 import org.netbeans.spi.project.support.ant.GeneratedFilesHelper; 28 import org.openide.filesystems.*; 29 30 32 41 public final class RegenerateFilesTask extends Task { 42 43 44 public RegenerateFilesTask() {} 45 46 private File buildXsl; 47 51 public void setBuildXsl(File f) { 52 buildXsl = f; 54 } 55 56 private File buildImplXsl; 57 61 public void setBuildImplXsl(File f) { 62 buildImplXsl = f; 63 } 64 65 private File projectDir; 66 70 public void setProject(File f) { 71 projectDir = f; 72 } 73 74 public void execute() throws BuildException { 75 if (projectDir == null) { 76 throw new BuildException("Must set 'project' attr", getLocation()); 77 } 78 if (buildXsl == null && buildImplXsl == null) { 80 throw new BuildException("Must set either 'buildxsl' or 'buildimplxsl' attrs or both", getLocation()); 81 } 82 try { 83 FileObject projectFO = FileUtil.toFileObject(projectDir); 85 if (projectFO == null) { 86 LocalFileSystem lfs = new LocalFileSystem(); 90 lfs.setRootDirectory(projectDir); 91 Repository.getDefault().addFileSystem(lfs); 92 projectFO = lfs.getRoot(); 93 assert projectFO != null; 94 } 95 GeneratedFilesHelper h = new GeneratedFilesHelper(projectFO); 96 if (buildXsl != null && h.refreshBuildScript(GeneratedFilesHelper.BUILD_XML_PATH, buildXsl.toURI().toURL(), true)) { 97 log("Regenerating " + new File (projectDir, GeneratedFilesHelper.BUILD_XML_PATH.replace('/', File.separatorChar)).getAbsolutePath()); 98 } 99 if (buildImplXsl != null && h.refreshBuildScript(GeneratedFilesHelper.BUILD_IMPL_XML_PATH, buildImplXsl.toURI().toURL(), true)) { 100 log("Regenerating " + new File (projectDir, GeneratedFilesHelper.BUILD_IMPL_XML_PATH.replace('/', File.separatorChar)).getAbsolutePath()); 101 } 102 } catch (IOException e) { 103 throw new BuildException(e, getLocation()); 104 } catch (PropertyVetoException e) { 105 throw new BuildException(e, getLocation()); 106 } 107 } 108 109 } 110 | Popular Tags |