public static Project getUnparented(File propertiesFile) throws Exception { propertiesFile = propertiesFile.getAbsoluteFile(); Workspace workspace = new Workspace(propertiesFile.getParentFile()); Project project = new Project(workspace, propertiesFile.getParentFile()); project.setProperties(propertiesFile); project.setFileMustExist(true); return project; }
@SuppressWarnings("unchecked") public void script(String type, String script) throws Exception { // TODO check tyiping List<Scripter> scripters = getPlugins(Scripter.class); if (scripters.isEmpty()) { error("Can not execute script because there are no scripters registered: %s", script); return; } @SuppressWarnings("rawtypes") Map x = (Map) getProperties(); scripters.get(0).eval((Map<String, Object>) x, new StringReader(script)); }
/** * This method must only be called when it is sure that the project has been * build before in the same session. It is a bit yucky, but ant creates * different class spaces which makes it hard to detect we already build it. * This method remembers the files in the appropriate instance vars. */ public File[] getBuildFiles() throws Exception { return getBuildFiles(true); }
/** * Parse the list of bundles that are a prerequisite to this project. * Bundles are listed in repo specific names. So we just let our repo * plugins iterate over the list of bundles and we get the highest version * from them. */ private List<Container> parseBuildpath() throws Exception { List<Container> bundles = getBundles(Strategy.LOWEST, mergeProperties(Constants.BUILDPATH), Constants.BUILDPATH); return bundles; }
/** * Parse the list of bundles that are a prerequisite to this project. * Bundles are listed in repo specific names. So we just let our repo * plugins iterate over the list of bundles and we get the highest version * from them. * * @return */ private List<Container> parseBuildpath() throws Exception { List<Container> bundles = getBundles(Strategy.LOWEST, getProperty(Constants.BUILDPATH), Constants.BUILDPATH); return bundles; }
public Project(Workspace workspace, File unused, File buildFile) { super(workspace); this.workspace = workspace; setFileMustExist(false); if (buildFile != null) setProperties(buildFile); // For backward compatibility reasons, we also read readBuildProperties(); }
protected void report(Map<String, Object> table, boolean isProject) throws Exception { if (isProject) { table.put("Target", getTarget()); table.put("Source", getSrc()); table.put("Output", getOutput()); File[] buildFiles = getBuildFiles(); if (buildFiles != null) table.put("BuildFiles", Arrays.asList(buildFiles)); table.put("Classpath", getClasspath()); table.put("Actions", getActions()); table.put("AllSourcePath", getAllsourcepath()); table.put("BootClassPath", getBootclasspath()); table.put("BuildPath", getBuildpath()); table.put("Deliverables", getDeliverables()); table.put("DependsOn", getDependson()); table.put("SourcePath", getSourcePath()); } table.put("RunPath", getRunpath()); table.put("TestPath", getTestpath()); table.put("RunProgramArgs", getRunProgramArgs()); table.put("RunVM", getRunVM()); table.put("Runfw", getRunFw()); table.put("Runbundles", getRunbundles()); }
strategy = Strategy.EXACT; else error("${repo;<bsn>;<version>;<'highest'|'lowest'|'exact'>} macro requires a strategy of 'highest' or 'lowest', and is " + args[3]); Collection<String> parts = split(bsns); List<String> paths = new ArrayList<String>(); Container container = getBundle(bsn, version, strategy, null); add(paths, container); return join(paths);
/** * This is the external method that will pre-build any dependencies if it is * out of date. * * @param underTest * @return * @throws Exception */ public File[] build(boolean underTest) throws Exception { if (isNoBundles()) return null; if (getProperty("-nope") != null) { warning("Please replace -nope with %s", NOBUNDLES); return null; } if (isStale()) { trace("building " + this); files = buildLocal(underTest); } return files; }
/** * Deploy the current project to a repository * * @throws Exception */ public void deploy() throws Exception { Parameters deploy = new Parameters(getProperty(DEPLOY)); if (deploy.isEmpty()) { warning("Deploying but %s is not set to any repo", DEPLOY); return; } File[] outputs = getBuildFiles(); for (File output : outputs) { for (Deploy d : getPlugins(Deploy.class)) { trace("Deploying %s to: %s", output.getName(), d); try { if (d.deploy(this, output.getName(), new BufferedInputStream(new FileInputStream(output)))) trace("deployed %s successfully to %s", output, d); } catch (Exception e) { msgs.Deploying(e); } } } }
private void reportNewer(long lastModified, Jar jar) { if (isTrue(getProperty(Constants.REPORTNEWER))) { StringBuilder sb = new StringBuilder(); String del = "Newer than " + new Date(lastModified); for (Map.Entry<String,Resource> entry : jar.getResources().entrySet()) { if (entry.getValue().lastModified() > lastModified) { sb.append(del); del = ", \n "; sb.append(entry.getKey()); } } if (sb.length() > 0) warning(sb.toString()); } }
strategy = STRATEGY_LOWEST; else error("${repo;<bsn>;<version>;<'highest'|'lowest'>} macro requires a strategy of 'highest' or 'lowest', and is " + args[3]); Collection<String> parts = split(bsns); List<String> paths = new ArrayList<String>(); Container jar = getBundle(bsn, version, strategy, null); if (jar.getError() == null) { paths.add(jar.getFile().getAbsolutePath()); } else { error("The ${repo} macro could not find " + bsn + " in the repo, because " + jar.getError() + "\n" + "Repositories : " + getPlugins(RepositoryPlugin.class) + "\n" + "Strategy : " + strategy + "\n" + "Bsn : " + bsn + ";version=" + version); return join(paths);
/** * This is the external method that will pre-build any dependencies if it is * out of date. * * @param underTest * @throws Exception */ public File[] build(boolean underTest) throws Exception { if (isNoBundles()) return null; if (getProperty("-nope") != null) { warning("Please replace -nope with %s", NOBUNDLES); return null; } logger.debug("building {}", this); File[] files = buildLocal(underTest); install(files); return files; }
public void test(List<String> tests) throws Exception { String testcases = getProperties().getProperty(Constants.TESTCASES); if (testcases == null) { warning("No %s set", Constants.TESTCASES); return; } clear(); test(null, tests); }
public File[] getBuildFiles(boolean buildIfAbsent) throws Exception { if (files != null) return files; File f = new File(getTarget(), BUILDFILES); if (f.isFile()) { FileReader fin = new FileReader(f); BufferedReader rdr = new BufferedReader(fin); try { List<File> files = newList(); for (String s = rdr.readLine(); s != null; s = rdr.readLine()) { s = s.trim(); File ff = new File(s); if (!ff.isFile()) { error("buildfile lists file but the file does not exist %s", ff); } else files.add(ff); } return this.files = files.toArray(new File[files.size()]); } finally { fin.close(); } } if (buildIfAbsent) return files = buildLocal(false); else return files = null; }
public File[] getBuildFiles(boolean buildIfAbsent) throws Exception { File[] current = files; if (current != null) { return current; } File bfs = new File(getTarget(), BUILDFILES); if (bfs.isFile()) { try (BufferedReader rdr = IO.reader(bfs)) { List<File> list = newList(); for (String s = rdr.readLine(); s != null; s = rdr.readLine()) { s = s.trim(); File ff = new File(s); if (!ff.isFile()) { // Originally we warned the user // but lets just rebuild. That way // the error is not noticed but // it seems better to correct, // See #154 rdr.close(); IO.delete(bfs); return files = buildIfAbsent ? buildLocal(false) : null; } list.add(ff); } return files = list.toArray(new File[0]); } } return files = buildIfAbsent ? buildLocal(false) : null; }
private void install(File[] files) throws Exception { if (files == null) return; Parameters p = getInstallRepositories(); for (Map.Entry<String, Attrs> e : p.entrySet()) { RepositoryPlugin rp = getWorkspace().getRepository(e.getKey()); if (rp != null) { for (File f : files) { install(f, rp, e.getValue()); } } else warning("No such repository to install into: %s", e.getKey()); } }
private void verifyDependencies(String title, Collection<Container> path) throws Exception { List<String> msgs = new ArrayList<String>(); for (Container c : new ArrayList<Container>(path)) { for (Container cc : c.getMembers()) { if (cc.getError() != null) msgs.add(cc + " - " + cc.getError()); else if (!cc.getFile().isFile() && !cc.getFile().equals(cc.getProject().getOutput()) && !cc.getFile().equals(cc.getProject().getTestOutput())) msgs.add(cc + " file does not exists: " + cc.getFile()); } } if (msgs.isEmpty()) return; error("%s: has errors: %s", title, Strings.join(msgs)); }
@Override public Entry<String, Resource> export(String type, Project project, Map<String, String> options) throws Exception { project.prepare(); Collection<Container> runbundles = project.getRunbundles(); Jar jar = new Jar(project.getName()); jar.setDoNotTouchManifest(); for (Container container : runbundles) { File source = container.getFile(); String path = nonCollidingPath(jar, source.getName()); jar.putResource(path, new FileResource(source)); } return new SimpleEntry<>(jar.getName(), new JarResource(jar, true)); }
public Version getVersion(String bsn) throws Exception { Version version = getVersions().get(bsn); if (version == null) { throw new IllegalArgumentException("Bsn " + bsn + " does not exist in project " + getName()); } return version; }