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

The following examples show how to use org.apache.tools.ant.Project#addReference() . 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: CosUpdated.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 2
Source File: RootLoaderRef.java    From groovy with Apache License 2.0 6 votes vote down vote up
public void execute() throws BuildException {
    if (taskClasspath == null || taskClasspath.size() == 0) {
        throw new BuildException("no classpath given");
    }
    Project project = getProject();
    String[] list = taskClasspath.list();
    LoaderConfiguration lc = new LoaderConfiguration();
    for (String s : list) {
        if (s.matches(".*ant-[^/]*jar$")) {
            continue;
        }
        if (s.matches(".*commons-logging-[^/]*jar$")) {
            continue;
        }
        if (s.matches(".*xerces-[^/]*jar$")) {
            continue;
        }
        lc.addFile(s);
    }
    AntClassLoader loader = AccessController.doPrivileged((PrivilegedAction<AntClassLoader>) () -> new AntClassLoader(new RootLoader(lc), true));
    project.addReference(name, loader);
}
 
Example 3
Source File: AntBuilder.java    From groovy with Apache License 2.0 6 votes vote down vote up
/**
 * @return Factory method to create new Project instances
 */
protected static Project createProject() {
    final Project project = new Project();

    final ProjectHelper helper = ProjectHelper.getProjectHelper();
    project.addReference(ProjectHelper.PROJECTHELPER_REFERENCE, helper);
    helper.getImportStack().addElement("AntBuilder"); // import checks that stack is not empty 

    final BuildLogger logger = new NoBannerLogger();

    logger.setMessageOutputLevel(org.apache.tools.ant.Project.MSG_INFO);
    logger.setOutputPrintStream(System.out);
    logger.setErrorPrintStream(System.err);

    project.addBuildListener(logger);

    project.init();
    project.getBaseDir();
    return project;
}
 
Example 4
Source File: ShuffleModel.java    From Shuffle-Move with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Constructs the Project and returns it.
 * 
 * @return The Project
 * @throws Exception
 *            If anything goes wrong.
 */
private Project getErrorProject() throws Exception {
   Path buildFilePath = Paths.get(BUILD_REPORT_FILE);
   LOG.finer("Build file path set to " + String.valueOf(buildFilePath));
   Project p = new Project();
   p.setSystemProperties();
   p.setUserProperty("ant.file", buildFilePath.toAbsolutePath().toString());
   LOG.finer("Project ant.file property set.");
   p.init();
   LOG.finer("Project.init() called.");
   ProjectHelper helper = ProjectHelper.getProjectHelper();
   LOG.finer("ProjectHelper created.");
   p.addReference("ant.projectHelper", helper);
   LOG.finer("Project ant.projectHelper reference set.");
   p.addReference("user.dir", System.getProperty("user.dir"));
   LOG.finer("Project user.dir reference set.");
   helper.parse(p, buildFilePath.toAbsolutePath().toFile());
   LOG.finer("PrjectHelper.parse() called.");
   errorProject = p;
   p.addBuildListener(getBuildListener());
   LOG.finer("BuildListener added.");
   return errorProject;
}
 
Example 5
Source File: AntHarnessTest.java    From ExpectIt with Apache License 2.0 6 votes vote down vote up
private static Project newProject() throws IOException {
    setupBuildFile();
    Project project = new Project();
    project.setUserProperty("ant.file", buildFile.getAbsolutePath());
    project.init();
    DefaultLogger listener = new DefaultLogger();
    listener.setErrorPrintStream(System.err);
    listener.setOutputPrintStream(System.out);
    listener.setMessageOutputLevel(Project.MSG_INFO);
    ProjectHelper helper = ProjectHelper.getProjectHelper();
    project.addReference("ant.projectHelper", helper);
    project.setProperty("ftp.port", String.valueOf(ftpPort));
    project.setProperty("ssh.port", String.valueOf(sshPort));
    helper.parse(project, buildFile);
    project.addBuildListener(listener);
    return project;
}
 
Example 6
Source File: AntUtil.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * @return Factory method to create new Project instances
 */
public static Project createProject() {
    final Project project = new Project();

    final ProjectHelper helper = ProjectHelper.getProjectHelper();
    project.addReference(ProjectHelper.PROJECTHELPER_REFERENCE, helper);
    helper.getImportStack().addElement("AntBuilder"); // import checks that stack is not empty

    project.addBuildListener(new AntLoggingAdapter());

    project.init();
    project.getBaseDir();
    return project;
}
 
Example 7
Source File: AntUtil.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * @return Factory method to create new Project instances
 */
public static Project createProject() {
    final Project project = new Project();

    final ProjectHelper helper = ProjectHelper.getProjectHelper();
    project.addReference(ProjectHelper.PROJECTHELPER_REFERENCE, helper);
    helper.getImportStack().addElement("AntBuilder"); // import checks that stack is not empty

    project.addBuildListener(new AntLoggingAdapter());

    project.init();
    project.getBaseDir();
    return project;
}
 
Example 8
Source File: CreateDependenciesTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testDependencies() throws Exception {
    CreateDependencies d = new CreateDependencies();
    
    Project prj = new Project();
    DirSet ds = new DirSet();
    File dependencies = new File(nb_all, "dependencies");

    ds.setProject(prj);
    ds.setDir(nb_all);
    prj.addReference("x", ds);
    prj.setProperty("nb_all", nb_all.getAbsolutePath());
    d.setProject(prj);
    d.getProject();
    d.setRefid("x");
    d.setDependencies(dependencies);
    d.execute();

    assertFileContent(dependencies,
                      "This project's dependencies\n" +
                      "\n" +
                      "\n" +
                      "Runtime dependencies:\n" +
                      "=====================\n" +
                      "\n" +
                      "From: XC\n" +
                      "  - XA: XB (XD)\n" +
                      "    License: Test license\n" +
                      "\n");
}
 
Example 9
Source File: CreateDependenciesTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testCompileTimeDependencies() throws Exception {
    CreateDependencies d = new CreateDependencies();
    
    Project prj = new Project();
    DirSet ds = new DirSet();
    File dependencies = new File(nb_all, "dependencies");

    ds.setProject(prj);
    ds.setDir(nb_all);
    prj.addReference("x", ds);
    prj.setProperty("nb_all", nb_all.getAbsolutePath());
    d.setProject(prj);
    d.getProject();
    d.setRefid("x");
    d.setDependencies(dependencies);
    d.setSourceDependencies(true);
    d.execute();

    assertFileContent(dependencies,
                      "This project's dependencies\n" +
                      "\n" +
                      "\n" +
                      "Runtime dependencies:\n" +
                      "=====================\n" +
                      "\n" +
                      "From: XC\n" +
                      "  - XA: XB (XD)\n" +
                      "    License: Test license\n" +
                      "\n" +
                      "\n" +
                      "Compile time dependencies:\n" +
                      "==========================\n" +
                      "\n" +
                      "From: XC2\n" +
                      "  - XA2: XB2 (XD2)\n" +
                      "    License: Test license2\n" +
                      "\n");
}
 
Example 10
Source File: AntUtil.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * @return Factory method to create new Project instances
 */
public static Project createProject() {
    final Project project = new Project();

    final ProjectHelper helper = ProjectHelper.getProjectHelper();
    project.addReference(ProjectHelper.PROJECTHELPER_REFERENCE, helper);
    helper.getImportStack().addElement("AntBuilder"); // import checks that stack is not empty

    project.addBuildListener(new AntLoggingAdapter());

    project.init();
    project.getBaseDir();
    return project;
}
 
Example 11
Source File: AntUtil.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * @return Factory method to create new Project instances
 */
public static Project createProject() {
    final Project project = new Project();

    final ProjectHelper helper = ProjectHelper.getProjectHelper();
    project.addReference(ProjectHelper.PROJECTHELPER_REFERENCE, helper);
    helper.getImportStack().addElement("AntBuilder"); // import checks that stack is not empty

    project.addBuildListener(new AntLoggingAdapter());

    project.init();
    project.getBaseDir();
    return project;
}
 
Example 12
Source File: IvyAntSettings.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the default ivy settings of this classloader. If it doesn't exist yet, a new one is
 * created using the given project to back the VariableContainer.
 *
 * @param task
 *            TODO add text.
 * @return An IvySetting instance.
 */
public static IvyAntSettings getDefaultInstance(ProjectComponent task) {
    Project project = task.getProject();
    Object defaultInstanceObj = project.getReference("ivy.instance");
    if (defaultInstanceObj != null
            && defaultInstanceObj.getClass().getClassLoader() != IvyAntSettings.class
                    .getClassLoader()) {
        task.log("ivy.instance reference an ivy:settings defined in an other classloader.  "
                + "An new default one will be used in this project.", Project.MSG_WARN);
        defaultInstanceObj = null;
    }
    if (defaultInstanceObj != null && !(defaultInstanceObj instanceof IvyAntSettings)) {
        throw new BuildException("ivy.instance reference a "
                + defaultInstanceObj.getClass().getName()
                + " an not an IvyAntSettings.  Please don't use this reference id ()");
    }
    if (defaultInstanceObj == null) {
        task.log("No ivy:settings found for the default reference 'ivy.instance'.  "
                + "A default instance will be used", Project.MSG_VERBOSE);

        IvyAntSettings settings = new IvyAntSettings();
        settings.setProject(project);
        project.addReference("ivy.instance", settings);
        settings.createIvyEngine(task);
        return settings;
    } else {
        return (IvyAntSettings) defaultInstanceObj;
    }
}
 
Example 13
Source File: IvyTaskTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testReferencedSettings() throws MalformedURLException {
    Project p = TestHelper.newProject();
    p.setProperty("myproperty", "myvalue");

    IvyAntSettings antSettings = new IvyAntSettings();
    antSettings.setProject(p);
    // antSettings.setId("mySettings");
    antSettings.setFile(new File("test/repositories/ivysettings.xml"));
    p.addReference("mySettings", antSettings);

    IvyTask task = new IvyTask() {
        public void doExecute() throws BuildException {
        }
    };
    task.setProject(p);
    task.setSettingsRef(new Reference(task.getProject(), "mySettings"));
    Ivy ivy = task.getIvyInstance();
    assertNotNull(ivy);
    IvySettings settings = ivy.getSettings();
    assertNotNull(settings);

    assertEquals(new File("build/cache").getAbsoluteFile(), settings.getDefaultCache());
    assertEquals(new File("test/repositories/ivysettings.xml").getAbsolutePath(), settings
            .getVariables().getVariable("ivy.settings.file"));
    assertEquals(
        new File("test/repositories/ivysettings.xml").toURI().toURL().toExternalForm(),
        settings.getVariables().getVariable("ivy.settings.url"));
    assertEquals(new File("test/repositories").getAbsolutePath(), settings.getVariables()
            .getVariable("ivy.settings.dir"));
    assertEquals("myvalue", settings.getVariables().getVariable("myproperty"));
}
 
Example 14
Source File: Main.java    From scava with Eclipse Public License 2.0 4 votes vote down vote up
public static void main(String[] args) {

		Vector<Target> targets = new Vector<Target>();

		Target m2mTarget = new Target();
		m2mTarget.setName(M2M);
		Target m2tTarget = new Target();
		m2tTarget.setName(M2T);
		Target setupTarget = new Target();
		setupTarget.setName(SETUP);

		File buildFile = new File(BUILD_XML);
		Project p = new Project();
		p.setUserProperty(ANT_FILE, buildFile.getAbsolutePath());
		p.init();
		ProjectHelper helper = ProjectHelper.getProjectHelper();
		p.addReference(ANT_PROJECT_HELPER, helper);
		helper.parse(p, buildFile);

		Scanner scanner = new Scanner(System.in);
		while (true){
			System.out.println("Which transformation would you like to start? (M2M / M2T) : ");
			String target = scanner.next();
			if (target.equals(M2M)){
				System.out.println("Select the OpenAPI JSON schema to transform.");
				try {
					TimeUnit.MILLISECONDS.sleep(500);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				JFileChooser chooser = new JFileChooser();
				chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
				chooser.setCurrentDirectory(new File(SCHEMAS_DIR));
				
				chooser.showOpenDialog(null);
				File selectedFile = chooser.getSelectedFile();
				if (selectedFile.isFile() && selectedFile.getName().endsWith(".json")){
					System.out.println(selectedFile.getName());
					
					targets.add(m2mTarget);
					break;
				} else {
					chooser = null;
					System.out.println("Something went wrong");
				}
				//p.executeSortedTargets(targets);
			} else if (target.equals(M2M)){
				//p.executeTarget(p.getDefaultTarget());
				break;
			} else { 
				System.out.println("Invalid");
			}

		}
		scanner.close();

	}
 
Example 15
Source File: BundleClasspathTask.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void execute() throws BuildException {
  if (   (null==propertyName || 0==propertyName.length())
         && (null==filesetId    || 0==filesetId.length()) ) {
    throw new BuildException
      ("Either propertyName or filesetId must be given.");
  }
  if (null!=filesetId && dir==null) {
    throw new BuildException
      ("dir is required when filesetId is given.");
  }

  if (null==bundleClasspath || 0==bundleClasspath.length() ) {
    bundleClasspath = ".";
  }

  final StringBuffer sb = new StringBuffer(100);

  // Convert path entries to patterns.
  final StringTokenizer st = new StringTokenizer(bundleClasspath, ",");
  while (st.hasMoreTokens()) {
    String entry = st.nextToken().trim();
    if (entry.startsWith("/")) {
      // Entry is a relative path, must not start with a '/', fix it.
      entry = entry.substring(1);
    }

    if (".".equals(entry)) {
      sb.append("**/*.class");
    } else if (entry.endsWith(".jar")) {
      sb.append(entry);
    } else {
      sb.append(entry + "/**/*.class");
    }
    if (st.hasMoreTokens()) {
      sb.append(",");
    }
  }

  final Project proj = getProject();

  // Conversion done - write back properties
  if (null!=propertyName) {
    proj.setProperty(propertyName, sb.toString());
    log("Converted \"" +bundleClasspath +"\" to pattern \""
        +sb.toString() +"\"",
        Project.MSG_VERBOSE);
  }

  if (null!=filesetId) {
    final FileSet fileSet = new FileSet();
    fileSet.setProject(proj);
    if (dir.exists()) {
      fileSet.setDir(dir);
      fileSet.setIncludes(sb.toString());
    } else {
      log("Bundle class path root dir '" +dir
          +"' does not exist, returning empty file set.",
          Project.MSG_DEBUG);
      fileSet.setDir(new File("."));
      fileSet.setExcludes("**/*");
    }
    proj.addReference(filesetId, fileSet);
    log("Converted bundle class path \"" +bundleClasspath
        +"\" to file set with id '" +filesetId
        +"' and files \"" +fileSet +"\"",
        Project.MSG_VERBOSE);
  }
}