public synchronized void messageLogged(BuildEvent event) { final boolean failOnError = isFailOnError(event); if (sendException(event, failOnError)) { return; } int priority = event.getPriority(); if (priority == Project.MSG_ERR && !failOnError) { // some ant tasks (like Copy) with 'failOnError' attribute set to 'false' // send warnings with priority level = Project.MSG_ERR // this heuristic corrects the priority level, so that IDEA considers the message not as an error but as a warning priority = Project.MSG_WARN; } final String message = event.getMessage(); if (priority == Project.MSG_ERR) { myMessagePriority.sendMessage(ERROR, priority, message); } else { myMessagePriority.sendMessage(MESSAGE, priority, message); } }
/** * Ask redirector to close all the streams. It is necessary to call this method * before leaving the Task to have the Streams flush their contents. If you are * collecting output in a property, it will be created only if this method is * called, otherwise you'll find it unset. */ protected void closeRedirector() { try { if (redirectOutput) { redirector.complete(); } } catch (IOException ioe) { log("Error closing redirector: " + ioe.getMessage(), Project.MSG_ERR); } /* * Due to depends chain, Ant could call the Task more than once, * this is to prevent that we attempt to reuse the previuosly * closed Streams. */ redirectOutStream = null; redirectOutPrintStream = null; redirectErrStream = null; redirectErrPrintStream = null; }
private boolean isTarget( final String propName, final File... targets) { final Project p = getProject(); final String propVal = p.getProperty(propName); if (propVal == null) { return false; } final File resolvedFile = p.resolveFile(propVal); if (resolvedFile == null) { return false; } final File normalizedResolvedFile = FileUtil.normalizeFile(resolvedFile); for (File target : targets) { if (target == null) { continue; } final File normalizedTarget = FileUtil.normalizeFile(target); if (isParentOf(normalizedTarget, normalizedResolvedFile)) { return true; } } return false; }
/** * Invoke the Hadoop record compiler on each record definition file */ @Override public void execute() throws BuildException { if (src == null && filesets.size()==0) { throw new BuildException("There must be a file attribute or a fileset child element"); } if (src != null) { doCompile(src); } Project myProject = getProject(); for (int i = 0; i < filesets.size(); i++) { FileSet fs = filesets.get(i); DirectoryScanner ds = fs.getDirectoryScanner(myProject); File dir = fs.getDir(myProject); String[] srcs = ds.getIncludedFiles(); for (int j = 0; j < srcs.length; j++) { doCompile(new File(dir, srcs[j])); } } }
@Override protected void setUp() throws Exception { clearWorkDir(); dist = new File(getWorkDir(), "dist"); dist.mkdirs(); src = new File(getWorkDir(), "src"); src.mkdirs(); Project p = new Project(); task = new LocFiles(); task.setProject(p); task.setCluster("platform"); task.setLocales("cs"); task.setPatternSet("pattern.set"); task.setSrc(src); task.setDestDir(dist); }
private String classToSourceURL (FileObject fo) { try { ClassPath cp = ClassPath.getClassPath (fo, ClassPath.EXECUTE); FileObject root = cp.findOwnerRoot (fo); String resourceName = cp.getResourceName (fo, '/', false); if (resourceName == null) { getProject().log("Can not find classpath resource for "+fo+", skipping...", Project.MSG_ERR); return null; } int i = resourceName.indexOf ('$'); if (i > 0) resourceName = resourceName.substring (0, i); FileObject[] sRoots = SourceForBinaryQuery.findSourceRoots (root.getURL ()).getRoots (); ClassPath sourcePath = ClassPathSupport.createClassPath (sRoots); FileObject rfo = sourcePath.findResource (resourceName + ".java"); if (rfo == null) return null; return rfo.getURL ().toExternalForm (); } catch (FileStateInvalidException ex) { ex.printStackTrace (); return null; } }
private void processLocale(String locale, Collection<? super String> toAdd, boolean warn) { File baseSrcDir = fileFrom(srcDir, locale); if (!baseSrcDir.exists()) { if (warn) { log("No files for locale: " + locale); } return; } log("Found L10N dir " + baseSrcDir, Project.MSG_VERBOSE); final String moduleDir = findModuleDir(cnbDashes); File locBaseDir = fileFrom(baseSrcDir, cluster, moduleDir); if (!locBaseDir.exists()) { log("Can't find directory " + locBaseDir, Project.MSG_WARN); return; } File[] ch = locBaseDir.listFiles(); if (ch == null) { throw new BuildException("Surprising content of " + locBaseDir); } for (File f : ch) { processLocaleJar(f, locale, toAdd, moduleDir, locBaseDir, baseSrcDir); } }
@Override public void execute() { Project p = getProject(); Properties props = readProperties(propertyFile); toolName = props.getProperty("tool.name"); if (toolName != null) { toolArgs = props.getProperty(toolName + ".args", ""); } if (toolProperty == null || askIfUnset && (toolName == null || (argsProperty != null && toolArgs == null))) { showGUI(props); } // finally, return required values, if any if (toolProperty != null && !(toolName == null || toolName.equals(""))) { p.setProperty(toolProperty, toolName); if (argsProperty != null && toolArgs != null) p.setProperty(argsProperty, toolArgs); } }
static void validateAgainstAUDTDs(InputSource input, final Path updaterJar, final Task task) throws IOException, SAXException { XMLUtil.parse(input, true, false, XMLUtil.rethrowHandler(), new EntityResolver() { ClassLoader loader = new AntClassLoader(task.getProject(), updaterJar); public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { String remote = "http://www.netbeans.org/dtds/"; if (systemId.startsWith(remote)) { String rsrc = "org/netbeans/updater/resources/" + systemId.substring(remote.length()); URL u = loader.getResource(rsrc); if (u != null) { return new InputSource(u.toString()); } else { task.log(rsrc + " not found in " + updaterJar, Project.MSG_WARN); } } return null; } }); }
private boolean determineParameter(File moduleFile, String parameter) throws IOException { String name = moduleFile.getName(); name = name.substring(0, name.length() - 3) + "xml"; File configFile = new File(moduleFile.getParentFile().getParentFile(), "config/Modules/" + name); log ("config " + configFile, Project.MSG_DEBUG); if (!configFile.exists()) return true; // probably a classpath module, treat like autoload final String fragment = "<param name=\"" + parameter + "\">true</param>"; try (BufferedReader br = new BufferedReader (new FileReader (configFile))) { String line; while ((line = br.readLine ()) != null) { if (line.indexOf (fragment) != -1) { log ("autoload module: " + moduleFile, Project.MSG_DEBUG); return true; } } } return false; }
@Override public void execute() throws BuildException { File tmpFile = null; try { if (isSigned(jar) == null) { tmpFile = extendLibraryManifest(getProject(), jar, destJar, codebase, permissions, appName); } } catch (IOException | ManifestException ex) { getProject().log( "Failed to extend libraries manifests: " + ex.getMessage(), //NOI18N Project.MSG_WARN); } if (tmpFile != null) { sign(tmpFile, destJar); deleteTmpFile(tmpFile); } else { sign(jar, destJar); } }
/** * Signs the given files according to the signJars variable value. */ private void sign(File from, File to) { if (!from.exists() && from.getParentFile().getName().equals("locale")) { // skip missing locale files, probably the best fix for #103301 log("Localization file " + from + " is referenced, but cannot be found. Skipping.", Project.MSG_WARN); return; } getSignTask().setJar(from); if (to != null) { // #125970: might be .../modules/locale/something_ja.jar to.getParentFile().mkdirs(); } getSignTask().setSignedjar(to); // use reflection for calling getSignTask().setDigestAlg("SHA1"); getSignTask().setDigestAlg("SHA1"); getSignTask().execute(); }
static ClassPath createSourcePath ( Project project, Path modulepath, Path classpath, Path sourcepath, boolean isSourcePathExclusive ) { if (sourcepath != null && isSourcePathExclusive) { return convertToClassPath (project, sourcepath); } ClassPath cp = convertToSourcePath (project, classpath, true); ClassPath modulesSources = convertToSourcePath(project, modules(project, modulepath), true); ClassPath sp = convertToClassPath (project, sourcepath); ClassPath sourcePath = ClassPathSupport.createProxyClassPath ( new ClassPath[] {cp, modulesSources, sp} ); return sourcePath; }
/** * Description of the Method * * @param tp */ private void loadTextProps( String tp ) { Properties p = new Properties(); Project project = getProject(); StringTokenizer st = new StringTokenizer( tp, "$" ); while ( st.hasMoreTokens() ) { String token = st.nextToken(); int start = token.indexOf( "{" ); int end = token.indexOf( "}" ); if ( start > -1 && end > -1 && end > start ) { String name = token.substring( start + 1, end - start ); String value = project.getProperty( name ); if ( value != null ) p.setProperty( name, value ); } } addProperties( p ); }
static ClassPath createJDKSourcePath ( Project project, Path bootclasspath ) { if (bootclasspath == null) { // if current platform is default one, bootclasspath is set to null JavaPlatform jp = JavaPlatform.getDefault(); if (jp != null) { return jp.getSourceFolders (); } else { return ClassPathSupport.createClassPath(java.util.Collections.EMPTY_LIST); } } else { return convertToSourcePath (project, bootclasspath, false); } }
public static void compress(String desPath, String srcPath){ File desFile = new File(desPath);// 目标文件 File srcFile = new File(srcPath);// 源文件 if (!srcFile.exists()) throw new RuntimeException("需要压缩的文件不存在"); Project project = new Project(); Zip zip = new Zip(); zip.setProject(project); zip.setDestFile(desFile); FileSet fileSet = new FileSet(); fileSet.setProject(project); fileSet.setDir(srcFile); zip.addFileset(fileSet); zip.execute(); }
/** Execute this task. */ public void execute () throws BuildException { if ( values.isEmpty() ) { throw new BuildException("You must set at least one value!", getLocation()); } if ( target == null ) { throw new BuildException("Target must be set!", getLocation()); } for (String val : values) { log ("Process '" + val + "' location with '" + target + "' target ...", Project.MSG_VERBOSE); CallTarget antCall = (CallTarget) getProject().createTask("antcall"); antCall.init(); antCall.setLocation(getLocation()); // ant.setDir (dir); antCall.setTarget (target); Property prop = antCall.createParam(); prop.setName(name); prop.setValue(val); antCall.execute(); } }
/** * Rather than adding properties to the project, add mapping hints * to the task. */ @Override protected void addProperty(String n, Object vObj) { String v = (vObj == null) ? null : vObj.toString(); try { // resolve relative paths against project basedir File source = getProject().resolveFile(n); // add a trailing slash to the hint target if necessary if(source.isDirectory() && v != null && !v.endsWith("/")) { v += "/"; } mappingHints.put(source.toURI().toURL(), absolute ? null : v); } catch(MalformedURLException e) { PackageGappTask.this.log("Couldn't interpret \"" + n + "\" as a file path, ignored", Project.MSG_WARN); } }
/** * Find all modules in a binary build, possibly from cache. */ private static Map<String,Entry> scanBinaries(Project project, File[] clusters) throws IOException { Map<String,Entry> allEntries = new HashMap<>(); for (File cluster : clusters) { Map<String, Entry> entries = BINARY_SCAN_CACHE.get(cluster); if (entries == null) { if (project != null) { project.log("Scanning for modules in " + cluster); } entries = new HashMap<>(); doScanBinaries(cluster, entries); if (project != null) { project.log("Found modules: " + entries.keySet(), Project.MSG_VERBOSE); } BINARY_SCAN_CACHE.put(cluster, entries); } allEntries.putAll(entries); } return allEntries; }
private static void doScanSuite(Map<String,Entry> entries, File suite, Map<String,Object> properties, Project project) throws IOException { Project fakeproj = new Project(); fakeproj.setBaseDir(suite); // in case ${basedir} is used somewhere Property faketask = new Property(); faketask.setProject(fakeproj); faketask.setFile(new File(suite, "nbproject/private/private.properties".replace('/', File.separatorChar))); faketask.execute(); faketask.setFile(new File(suite, "nbproject/project.properties".replace('/', File.separatorChar))); faketask.execute(); String modulesS = fakeproj.getProperty("modules"); if (modulesS == null) { throw new IOException("No definition of modules in " + suite); } String[] modules = Path.translatePath(fakeproj, modulesS); for (int i = 0; i < modules.length; i++) { File module = new File(modules[i]); if (!module.isDirectory()) { throw new IOException("No such module " + module + " referred to from " + suite); } if (!scanPossibleProject(module, entries, properties, null, ModuleType.SUITE, project, null)) { throw new IOException("No valid module found in " + module + " referred to from " + suite); } } }
private void scanForProjectDirs(File fl) { if (depth > userDepth) return; //if (isProjectDir(fl)) { // projectDirList.add(fl); //} File allFiles[] = fl.listFiles(new FileFilter() { public boolean accept(File pathname) { if (pathname.isDirectory()) { return true; } return false; } }); depth++; for (File f : allFiles) { if (isProjectDir(f)) { // here could be some project exclusion logic projectDirList.add(f); log(f.toString(), Project.MSG_VERBOSE); scanForProjectDirs(f); } else { scanForProjectDirs(f); } } depth--; }
/** * @param property The property * @param value The value * @return True if successful */ public boolean setProperty(String property, Object value) { if (property != null) { if (value == null) value = ""; if (isEcho()) { handleOutput(property + "=" + value.toString()); } Project currentProject = getProject(); if (currentProject != null) { currentProject.setNewProperty(property, value.toString()); } else { properties.setProperty(property, value.toString()); } return true; } return false; }
@Override public void execute() throws BuildException { if (this.id == null || this.id.isEmpty()) { throw new BuildException("The id has to be set."); //NOI18N } if (this.srcdir == null || !this.srcdir.isDirectory()) { throw new BuildException("The srcdir has to point to a directory."); //NOI18N } if (this.includes == null || this.includes.isEmpty()) { throw new BuildException("The includes has to be set."); //NOI18N } final Project prj = getProject(); final CosFileSet cfs = new CosFileSet(); cfs.setProject(prj); cfs.setDir(this.srcdir); for (String include : includes.split(",")) { //NOI18N include = include.trim(); if (!include.isEmpty()) { cfs.createInclude().setName(include); } } prj.addReference(this.id, cfs); }
/** * Ask redirector to close all the streams. It is necessary to call this * method before leaving the Task to have the Streams flush their contents. * If you are collecting output in a property, it will be created only if * this method is called, otherwise you'll find it unset. */ protected void closeRedirector() { try { if (redirectOutput && redirectOutPrintStream != null) { redirector.complete(); } } catch (IOException ioe) { log("Error closing redirector: " + ioe.getMessage(), Project.MSG_ERR); } /* * Due to depends chain, Ant could call the Task more than once, this is * to prevent that we attempt to reuse the previously closed Streams. */ redirectOutStream = null; redirectOutPrintStream = null; redirectErrStream = null; redirectErrPrintStream = null; }
/** Returns true if either a manifest or a module must be specified. * This is true unless either the global property * makenbm.manOrModReq is false, or the manOrModReq attribute of * this task is false. The attribute, if set, has priority over the * global property. */ public boolean reqManOrMod() { boolean req = true ; if( manOrModReqSet) { req = manOrModReq ; } else { String s = getProject().getProperty("makenbm.manOrModReq"); //NOI18N if( s != null && !s.equals( "")) { //NOI18N req = Project.toBoolean(s); } } return( req) ; }
/** * Signs or copies the given files according to the signJars variable value. */ private void signOrCopy(File from, File to) { if (!from.exists() && from.getParentFile().getName().equals("locale")) { // skip missing locale files, probably the best fix for #103301 log("Localization file " + from + " is referenced, but cannot be found. Skipping.", Project.MSG_WARN); return; } if (signJars) { getSignTask().setJar(from); if (to != null) { // #125970: might be .../modules/locale/something_ja.jar to.getParentFile().mkdirs(); } getSignTask().setSignedjar(to); getSignTask().setDigestAlg("SHA1"); getSignTask().execute(); } else if (to != null) { Copy copy = (Copy)getProject().createTask("copy"); copy.setFile(from); copy.setTofile(to); copy.execute(); } if (processJarVersions) { if (jarDirectories == null) { jarDirectories = new HashSet<>(); } jarDirectories.add(new File(to.getParent())); } }
/** * get all properties, when project is there got all project Properties * @return properties */ public Map getProperties() { Project currentProject = getProject(); if (currentProject != null) { return currentProject.getProperties(); } else { return properties; } }
public void close() { Project project = getProject(); project.fireBuildFinished(null); ComponentHelper helper = ComponentHelper.getComponentHelper(project); helper.getAntTypeTable().clear(); helper.getDataTypeDefinitions().clear(); project.getReferences().clear(); }
/** * Perform the conversion * * @throws BuildException if an error occurs during execution of * this task. */ @Override public void execute() throws BuildException { int count = 0; // Step through each file and convert. Iterator<FileSet> iter = filesets.iterator(); while( iter.hasNext() ) { FileSet fs = iter.next(); DirectoryScanner ds = fs.getDirectoryScanner(getProject()); File basedir = ds.getBasedir(); String[] files = ds.getIncludedFiles(); for( int i = 0; i < files.length; i++ ) { File from = new File( basedir, files[i] ); File to = new File( todir, files[i] + ".html" ); if( !to.exists() || (from.lastModified() > to.lastModified()) ) { log( "Converting file '" + from.getAbsolutePath() + "' to '" + to.getAbsolutePath(), Project.MSG_VERBOSE ); try { convert( from, to ); } catch( IOException e ) { throw new BuildException( "Could not convert '" + from.getAbsolutePath() + "' to '" + to.getAbsolutePath() + "'", e ); } count++; } } if( count > 0 ) { log( "Converted " + count + " file" + (count > 1 ? "s" : "") + " to " + todir.getAbsolutePath() ); } } }
static void verifyPaths(Project project, Path path) { if (path == null) return ; String[] paths = path.list(); for (int i = 0; i < paths.length; i++) { String pathName = project.replaceProperties(paths[i]); File file = FileUtil.normalizeFile (project.resolveFile (pathName)); if (!file.exists()) { project.log("Non-existing path \""+pathName+"\" provided.", Project.MSG_WARN); //throw new BuildException("Non-existing path \""+paths[i]+"\" provided."); } } }
public @Override void targetStarted(BuildEvent ev) { AntBridge.suspendDelegation(); try { checkForStop(); setLastTask(null); AntEvent e = LoggerTrampoline.ANT_EVENT_CREATOR.makeAntEvent(new Event(ev, false)); LOG.log(Level.FINE, "targetStarted: {0}", e); for (AntLogger l : getInterestedLoggersByEvent(e)) { try { l.targetStarted(e); } catch (RuntimeException x) { LOG.log(Level.WARNING, null, x); } } // Update progress handle label so user can see what is being run. Project p = ev.getProject(); String projectName = null; if (p != null) { projectName = p.getName(); } String targetName = e.getTargetName(); if (targetName != null) { String message; if (projectName != null) { message = NbBundle.getMessage(NbBuildLogger.class, "MSG_progress_target", projectName, targetName); } else { message = targetName; } /* if (message.equals(displayName)) { // Redundant in this case. message = ""; } */ handle.progress(message); } } finally { AntBridge.resumeDelegation(); } }
private Project getProjectIfPropertiesDefined() { Project project = e.getProject(); if (project != null && projectsWithProperties.contains(project)) { return project; } else { return null; } }
public void warning(SAXParseException exception) throws SAXException { if (exception.getLocalizedMessage().startsWith("Using original entity definition for")) { // Pointless message, always logged when using XHTML. Ignore. return; } log(exception.getSystemId() + ":" + exception.getLineNumber() + ": " + exception.getLocalizedMessage(), Project.MSG_WARN); }
/** * Creates a new builder for the given project. * * @param eclipseProject */ public PathBuilder(Project antProject, IEclipseProject eclipseProject, File workdir) { this.antProject = antProject; this.eclipseProject = eclipseProject; this.workdir = workdir; }
/** * Handles error output with the ERR priority. * * @param output The error output to log. Should not be <code>null</code>. */ @Override protected void handleErrorOutput(String output) { if (redirectOutput) { if (redirectErrPrintStream == null) { openRedirector(); } redirectErrPrintStream.println(output); if (alwaysLog) { log(output, Project.MSG_ERR); } } else { log(output, Project.MSG_ERR); } }
private static URL fileToURL (File file, Project project, boolean reportNonExistingFiles, boolean withSlash) { FileObject fileObject = FileUtil.toFileObject (file); if (fileObject == null) { if (reportNonExistingFiles) { String path = file.getAbsolutePath(); project.log("Have no file for "+path, Project.MSG_WARN); } return null; } if (FileUtil.isArchiveFile (fileObject)) { fileObject = FileUtil.getArchiveRoot (fileObject); if (fileObject == null) { project.log("Bad archive "+file.getAbsolutePath(), Project.MSG_WARN); /* ErrorManager.getDefault().notify(ErrorManager.getDefault().annotate( new NullPointerException("Bad archive "+file.toString()), NbBundle.getMessage(JPDAStart.class, "MSG_WrongArchive", file.getAbsolutePath()))); */ return null; } } if (withSlash) { return FileUtil.urlForArchiveOrDir(file); } else { return fileObject.toURL (); } }
public void setProcessErrorStream(InputStream inputStream) throws IOException { OutputStream os = getErrorStream(); Integer logLevel = null; if (os == null || delegateErrorStream) { os = AntBridge.delegateOutputStream(true); logLevel = Project.MSG_WARN; } errTask = new Thread(Thread.currentThread().getThreadGroup(), errCopier = new Copier(inputStream, os, logLevel, errEncoding, foldingHelper), "Err Thread for " + getProject().getName()); // NOI18N errTask.setDaemon(true); errTask.start(); }
/** * Setter for the 'project' property. * * @param project New value for the 'project' property. */ public static void setProject(final Project project) { Utils.project = project; useInternalPacker = "true".equals(project.getProperty("use.internal.packer")); useInternalUnpacker = "true".equals(project.getProperty("use.internal.unpacker")); xmx = ARG_PREFIX + XMX_ARG + project.getProperty("pack200.xmx"); permSize = ARG_PREFIX + PERM_SIZE_ARG + project.getProperty("pack200.perm.size"); maxPermSize = ARG_PREFIX + MAX_PERM_SIZE_ARG + project.getProperty("pack200.max.perm.size"); String output = "use.internal.packer? " + useInternalPacker; if (project != null) { project.log(" " + output); } else { System.out.println(output); } }
public Expander() { setProject(new Project()); getProject().init(); setTaskType("unzip"); setTaskName("unzip"); setOwningTarget(new Target()); }