/** * check for invalid options * * @throws BuildException if something goes wrong. */ protected void checkOptions() throws BuildException { // set the destination directory relative from the project if needed. if (toDir == null) { toDir = task.getProject().resolveFile("."); } else if (!toDir.isAbsolute()) { toDir = task.getProject().resolveFile(toDir.getPath()); } }
protected List<File> getSrc() { if (this.src == null) { return Collections.singletonList(task.getProject().resolveFile("source")); } String[] paths = this.src.list(); ArrayList<File> result = new ArrayList<File>(paths.length); for (String path : paths) { result.add(task.getProject().resolveFile(path)); } return result; }
/** * transformation * * @throws BuildException exception if something goes wrong with the transformation. */ public void transform() throws BuildException { checkOptions(); Project project = task.getProject(); TempFile tempFileTask = new TempFile(); tempFileTask.bindToOwner(task); XSLTProcess xsltTask = new XSLTProcess(); xsltTask.bindToOwner(task); xsltTask.setXslResource(getStylesheet()); // acrobatic cast. xsltTask.setIn(((XMLResultAggregator) task).getDestinationFile()); File outputFile = null; if (format.equals(FRAMES)) { String tempFileProperty = getClass().getName() + String.valueOf(counter++); File tmp = FILE_UTILS.resolveFile(project.getBaseDir(), project.getProperty("java.io.tmpdir")); tempFileTask.setDestDir(tmp); tempFileTask.setProperty(tempFileProperty); tempFileTask.execute(); outputFile = new File(project.getProperty(tempFileProperty)); } else { outputFile = new File(toDir, "junit-noframes.html"); } xsltTask.setOut(outputFile); for (Iterator i = params.iterator(); i.hasNext(); ) { XSLTProcess.Param param = (XSLTProcess.Param) i.next(); XSLTProcess.Param newParam = xsltTask.createParam(); newParam.setProject(task.getProject()); newParam.setName(param.getName()); newParam.setExpression(param.getExpression()); } XSLTProcess.Param paramx = xsltTask.createParam(); paramx.setProject(task.getProject()); paramx.setName("output.dir"); paramx.setExpression(toDir.getAbsolutePath()); final long t0 = System.currentTimeMillis(); try { xsltTask.execute(); } catch (Exception e) { throw new BuildException("Errors while applying transformations: " + e.getMessage(), e); } final long dt = System.currentTimeMillis() - t0; task.log("Transform time: " + dt + "ms"); if (format.equals(FRAMES)) { Delete delete = new Delete(); delete.bindToOwner(task); delete.setFile(outputFile); delete.execute(); } }
void handleExit(Task task, int sc, String message) { if (errorProperty != null) { task.getProject().setNewProperty(errorProperty, "true"); } if (failOnError) { throw new BuildException(message, task.getLocation()); } else { task.log(message, Project.MSG_ERR); } }
public Model loadModel( Task task, File pomFile, boolean local, RemoteRepositories remoteRepositories) { RepositorySystemSession session = getSession(task, null); remoteRepositories = remoteRepositories == null ? AetherUtils.getDefaultRepositories(project) : remoteRepositories; List<org.sonatype.aether.repository.RemoteRepository> repositories = ConverterUtils.toRepositories( task.getProject(), session, remoteRepositories, getRemoteRepoMan()); ModelResolver modelResolver = new AntModelResolver(session, "project", getSystem(), getRemoteRepoMan(), repositories); Settings settings = getSettings(); try { DefaultModelBuildingRequest request = new DefaultModelBuildingRequest(); request.setLocationTracking(true); request.setProcessPlugins(false); if (local) { request.setPomFile(pomFile); request.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_STRICT); } else { request.setModelSource(new FileModelSource(pomFile)); request.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL); } request.setSystemProperties(getSystemProperties()); request.setUserProperties(getUserProperties()); request.setProfiles(SettingsUtils.convert(settings.getProfiles())); request.setActiveProfileIds(settings.getActiveProfiles()); request.setModelResolver(modelResolver); return modelBuilder.build(request).getEffectiveModel(); } catch (ModelBuildingException e) { throw new BuildException("Could not load POM " + pomFile + ": " + e.getMessage(), e); } }
protected String getOut() { if (this.out == null) { return new File(task.getProject().getBaseDir(), "modules").getPath(); } return this.out; }
public CollectResult collectDependencies( Task task, Dependencies dependencies, LocalRepository localRepository, RemoteRepositories remoteRepositories) { RepositorySystemSession session = getSession(task, localRepository); remoteRepositories = remoteRepositories == null ? AetherUtils.getDefaultRepositories(project) : remoteRepositories; List<org.sonatype.aether.repository.RemoteRepository> repos = ConverterUtils.toRepositories(project, session, remoteRepositories, getRemoteRepoMan()); CollectRequest collectRequest = new CollectRequest(); collectRequest.setRequestContext("project"); for (org.sonatype.aether.repository.RemoteRepository repo : repos) { task.getProject().log("Using remote repository " + repo, Project.MSG_VERBOSE); collectRequest.addRepository(repo); } if (dependencies != null) { List<Exclusion> globalExclusions = dependencies.getExclusions(); Collection<String> ids = new HashSet<String>(); for (Dependency dep : dependencies.getDependencies()) { ids.add(dep.getVersionlessKey()); collectRequest.addDependency(ConverterUtils.toDependency(dep, globalExclusions, session)); } if (dependencies.getPom() != null) { Model model = dependencies.getPom().getModel(task); for (org.apache.maven.model.Dependency dep : model.getDependencies()) { Dependency dependency = new Dependency(); dependency.setArtifactId(dep.getArtifactId()); dependency.setClassifier(dep.getClassifier()); dependency.setGroupId(dep.getGroupId()); dependency.setScope(dep.getScope()); dependency.setType(dep.getType()); dependency.setVersion(dep.getVersion()); if (ids.contains(dependency.getVersionlessKey())) { continue; } if (dep.getSystemPath() != null && dep.getSystemPath().length() > 0) { dependency.setSystemPath(task.getProject().resolveFile(dep.getSystemPath())); } for (org.apache.maven.model.Exclusion exc : dep.getExclusions()) { Exclusion exclusion = new Exclusion(); exclusion.setGroupId(exc.getGroupId()); exclusion.setArtifactId(exc.getArtifactId()); exclusion.setClassifier("*"); exclusion.setExtension("*"); dependency.addExclusion(exclusion); } collectRequest.addDependency( ConverterUtils.toDependency(dependency, globalExclusions, session)); } } } task.getProject().log("Collecting dependencies", Project.MSG_VERBOSE); CollectResult result; try { result = getSystem().collectDependencies(session, collectRequest); } catch (DependencyCollectionException e) { throw new BuildException("Could not collect dependencies: " + e.getMessage(), e); } return result; }
/** * Define the path reference for compilation. * * @param pathRefId */ public void setPathRefId(String pathRefId) { this.path = (Path) parent.getProject().getReference(pathRefId); }