Java Code Examples for org.apache.tools.ant.Project#getProperty()

The following examples show how to use org.apache.tools.ant.Project#getProperty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DeleteTask.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 2
Source File: TestDistFilterTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void assertProperty(Project prj, String propName, String modules[]) throws IOException {
    String listModules = prj.getProperty(propName);
    assertNotNull("prop " + propName + " was not defined",listModules);
    log(" listModules " + listModules);
    String arrayModules[] = (listModules.length() == 0) ? new String[0] :listModules.split(":");
    Set<File> set1 = new HashSet<>();
    for (int i = 0 ; i < arrayModules.length ; i++) {
        String module = arrayModules[i];
        if (module.length() == 1 && i < arrayModules.length + 1) { 
            // module is e:/dd/dd/ on windows
            module = module + ":" + arrayModules[++i];
        }
        log(i + " = " + module );
        set1.add(new File(module)); 
    }
    Set<File> set2 = new HashSet<>();
    for (int i = 0 ; i < modules.length ; i++) {
        set2.add(new File(getWorkDir(),modules[i]));
    }
    assertEquals("paths length",set2.size(),set1.size());
    assertEquals("Different paths: ", set2,set1);
}
 
Example 3
Source File: ModuleListParser.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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);
        }
    }
}
 
Example 4
Source File: NbBuildLogger.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public @Override String getProperty(String name) {
    verifyRunning();
    Project project = getProjectIfPropertiesDefined();
    if (project != null) {
        String v = project.getProperty(name);
        if (v != null) {
            return v;
        } else {
            Object o = project.getReference(name);
            if (o != null) {
                return o.toString();
            } else {
                return null;
            }
        }
    } else {
        return null;
    }
}
 
Example 5
Source File: JMXAccessorTask.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Get Property
 * @param property name
 * @return The property value
 */
public String getProperty(String property) {
    Project currentProject = getProject();
    if (currentProject != null) {
        return currentProject.getProperty(property);
    } else {
        return properties.getProperty(property);
    }
}
 
Example 6
Source File: GenerateJnlpFileTask.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * SignJarsTask stores a project property with list of jars that have been signed
 * by a different keystore. These must not be referenced directly in jnlp but through
 * dedicated included jnlps. This method returns the list of such jars transferred from
 * SignJarsTask
 * @param prj
 * @return set of JAR file names
 */
private static Set<? extends String> getExternalJarsProp(final Project prj) {
    final Set<String> result = new HashSet<String>();
    final String extJarsProp = prj.getProperty(EXTERNAL_JARS_PROP);
    if(extJarsProp != null) {
        for(String extJar : extJarsProp.split(EXTERNAL_PROP_DELIMITER)) {
            if(!extJar.isEmpty()) {
                File f = new File(extJar);
                result.add(f.toString());
            }
        }
    }
    return result;
}
 
Example 7
Source File: GenerateJnlpFileTask.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * SignJarsTask stores a project property with list of jnlp component files that 
 * represent JARs signed by a different keystore. These need to be referenced 
 * from the main jnlp as external components.
 * @param prj
 * @return set of maps, each containing href and possibly other attributes representing a jnlp component
 */
private static Set<Map<String,String>> getExternalJnlpsProp(final Project prj) {
    final Set<Map<String,String>> result = new HashSet<Map<String,String>>();
    final String extJnlpsProp = prj.getProperty(EXTERNAL_JNLPS_PROP);
    if(extJnlpsProp != null) {
        for(String extJnlp : extJnlpsProp.split(EXTERNAL_PROP_DELIMITER)) {
            if(!extJnlp.isEmpty()) {
                Map<String, String> m = new HashMap<String, String>();
                m.put(EXT_RESOURCE_SUFFIXES[0], extJnlp);
                result.add(m);
            }
        }
    }
    return result;
}
 
Example 8
Source File: SetProperty.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Executes the task. If the source property was specified, its value is
 * evaluated and set as the value of the target property. Otherwise the literal
 * string value is used.
 */
public void execute() {        
    final Project project = getProject();
    final String string = (source != null) ? 
        project.getProperty(Utils.resolveProperty(source, project)) : 
        value;
    final String resolved = Utils.resolveProperty(string, project);
    log("Setting " + property + " to " + resolved);
    project.setProperty(property, resolved);
}
 
Example 9
Source File: NbBuildLogger.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Try to find the location of an Ant target.
 * @param project if not null, the main project from which this target might have been imported
 */
private Location getLocationOfTarget(Target target, Project project) {
    if (targetGetLocation != null) {
        try {
            return (Location) targetGetLocation.invoke(target);
        } catch (Exception e) {
            LOG.log(Level.WARNING, null, e);
        }
    }
    // For Ant 1.6.2 and earlier, hope we got the right info from the hacks above.
    LOG.log(Level.FINEST, "knownImportedTargets: {0}", knownImportedTargets);
    if (project != null) {
        String file = project.getProperty("ant.file"); // NOI18N
        if (file != null) {
            Map<String,String> targetLocations = knownImportedTargets.get(file);
            if (targetLocations != null) {
                String importedFile = targetLocations.get(target.getName());
                if (importedFile != null) {
                    // Have no line number, note.
                    return new Location(importedFile);
                }
            }
        }
    }
    // Dunno.
    return null;
}
 
Example 10
Source File: JMXAccessorTask.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Get Property
 * @param property name
 * @return The property value
 */
public String getProperty(String property) {
    Project currentProject = getProject();
    if (currentProject != null) {
        return currentProject.getProperty(property);
    } else {
        return properties.getProperty(property);
    }
}
 
Example 11
Source File: JMXAccessorTask.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Get Property
 * @param property name
 * @return The property value
 */
public String getProperty(String property) {
    Project currentProject = getProject();
    if (currentProject != null) {
        return currentProject.getProperty(property);
    } else {
        return properties.getProperty(property);
    }
}
 
Example 12
Source File: TaskJavaWebDSLUsed.java    From webdsl with Apache License 2.0 5 votes vote down vote up
public void execute() {
    Project project = getProject();
    String execcommand = project.getProperty("webdslexec");
    if(execcommand.startsWith("java")){
      project.setProperty("using-webdsl-java","true");
    }
}
 
Example 13
Source File: TaskBuildOptions.java    From webdsl with Apache License 2.0 5 votes vote down vote up
public void execute() {
    Project project = getProject();
    String buildoptions = project.getProperty("buildoptions");
    Pattern p = Pattern.compile("\\s");
    String[] commands = p.split(buildoptions);
    for(int i=0; i<commands.length; i++){
        project.setProperty("command"+i,commands[i]);
        Echo echo = (Echo) project.createTask("echo");
        echo.setMessage("command"+i+": "+commands[i]);
        echo.perform(); 	
    }
    project.setProperty("numberofcommands",""+commands.length);
}
 
Example 14
Source File: TaskApplicationIniTimestamp.java    From webdsl with Apache License 2.0 5 votes vote down vote up
public void execute() {
    Project project = getProject();
    String currentdir = project.getProperty("currentdir");
    File f = new File(currentdir+"/application.ini");
    Long datetime = f.lastModified();
    project.setProperty("current.application.ini.timestamp",datetime.toString());
}
 
Example 15
Source File: MakeHTMLTask.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private String links() {
  final Project proj = getProject();
  final StringBuffer buf = new StringBuffer();

  for (int i = 0; ; i++) {
    final String id   = proj.getProperty(LINK_ID + i);

    if (id == null) {
      break;
    }

    final String type = proj.getProperty(LINK_TYPE + i);
    if (type == null) {
      throw new BuildException("must set htdocs.link.type." + i);
    }

    if (type.equals("separator")) {
      buf.append("<p></p>");

    } else if (type.equals("link")) {

      final String name = proj.getProperty(LINK_NAME + i);
      final String url  = proj.getProperty(LINK_URL + i);
      if (name == null) {
        throw new BuildException("Name not set for htdocs.link.url." + i);
      }

      String cssClass = null;

      if (disable != null && disable.equals(id)) {
        cssClass = getProject().getProperty(CSS_CLASS_DISABLED);
      } else {
        cssClass = getProject().getProperty(CSS_CLASS_ENABLED);
      }

      buf.append("<a class=\"" + cssClass + "\" href=\"" + url
                 + "\">" + name + "</a><br/>\n");
    } else {
      throw new BuildException("Do not recognize type " + type);
    }
  }

  return buf.toString();
}
 
Example 16
Source File: TaskFixClasspath.java    From webdsl with Apache License 2.0 4 votes vote down vote up
public void execute() {
    Project project = getProject();

    String currentdir = project.getProperty("currentdir");
    String generatedir = project.getProperty("generate-dir");
    String webcontentdir = project.getProperty("webcontentdir");

    StringBuilder classpathFile = new StringBuilder();
    classpathFile.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
    classpathFile.append("<classpath>\n");
    classpathFile.append("\t<classpathentry kind=\"src\" path=\".servletapp/src-template\"/>\n");
    classpathFile.append("\t<classpathentry kind=\"src\" path=\".servletapp/src-generated\"/>\n");
    classpathFile.append("\t<classpathentry kind=\"src\" path=\"nativejava\"/>\n");
    classpathFile.append("\t<classpathentry kind=\"con\" path=\"org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6\"/>\n");
    classpathFile.append("\t<classpathentry kind=\"con\" path=\"org.eclipse.jst.j2ee.internal.web.container\"/>\n");
    classpathFile.append("\t<classpathentry kind=\"con\" path=\"org.eclipse.jst.j2ee.internal.module.container\"/>\n");
    classpathFile.append("\t<classpathentry kind=\"output\" path=\"").append(generatedir).append("/WEB-INF/classes\"/>\n"); //must use relative path here

    String filedir = webcontentdir+"/WEB-INF/lib"; //must use absolute path here
    File appdir = new File(filedir);
    Echo echo = (Echo) project.createTask("echo");
    echo.setMessage(filedir);
    echo.perform();
    File[] libfiles = appdir.listFiles();
    for (int i = 0 ; i < libfiles.length ; i ++ ) {
        if ( libfiles[i].isFile ( ) ){
            classpathFile.append("\t<classpathentry kind=\"lib\" path=\"").append(generatedir).append("/WEB-INF/lib/").append(libfiles[i].getName()).append("\"/>\n"); //must use relative path here
        }
    }
    classpathFile.append("</classpath>\n");

    try {
        //write result
        FileWriter fw = new FileWriter(currentdir+"/.classpath");
        BufferedWriter bw = new BufferedWriter(fw);
        bw.write(classpathFile.toString());
        bw.close();
        fw.close();
    } catch (Exception e) {
        Echo ec = (Echo) project.createTask("echo");
        ec.setMessage(e.getMessage());
        ec.perform();
    }
}