List of usage examples for org.apache.maven.project MavenProject getFile
public File getFile()
From source file:org.phpmaven.project.impl.ProjectPhpExecution.java
License:Apache License
/** * Adds additional include paths from dependency config. * @param execConfig/*from ww w . j a v a2s .com*/ * @param project * @param targetScope * @param depConfig * @param depsDir * @throws ExpressionEvaluationException */ private void addFromDepConfig(IPhpExecutableConfiguration execConfig, MavenProject project, String targetScope, IDependencyConfiguration depConfig, File depsDir) throws ExpressionEvaluationException, MojoExecutionException { final Set<Artifact> deps = project.getArtifacts(); for (final Artifact depObject : deps) { if (!targetScope.equals(depObject.getScope())) { continue; } MavenProject depProject; try { depProject = this.getProjectFromArtifact(project, depObject); } catch (ProjectBuildingException ex) { throw new ExpressionEvaluationException("Problems creating maven project from dependency", ex); } if (depProject.getFile() != null) { // Reference to a local project; should only happen in IDEs or multi-project poms for (final IAction action : DependencyHelper.getDependencyActions(depObject, depConfig, reposSystem, session, mavenProjectBuilder, componentFactory)) { if (action.getType() == ActionType.ACTION_INCLUDE) { final String includePath = getClassesDirFromProject(depProject) + "/" + ((IActionInclude) action).getPharPath(); execConfig.getIncludePath().add(new File(includePath).getAbsolutePath()); } else if (action.getType() == ActionType.ACTION_EXTRACT_INCLUDE) { final String includePath = getClassesDirFromProject(depProject) + "/" + ((IActionExtractAndInclude) action).getPharPath() + "/" + ((IActionExtractAndInclude) action).getIncludePath(); execConfig.getIncludePath().add(new File(includePath).getAbsolutePath()); } else if (action.getType() == ActionType.ACTION_CLASSIC) { final String includePath = getClassesDirFromProject(depProject); execConfig.getIncludePath().add(new File(includePath).getAbsolutePath()); } } } if (depObject.getFile() != null) { // Reference to a local repository for (final IAction action : DependencyHelper.getDependencyActions(depObject, depConfig, reposSystem, session, mavenProjectBuilder, componentFactory)) { if (action.getType() == ActionType.ACTION_INCLUDE) { final String includePath = ((IActionInclude) action).getPharPath(); execConfig.getIncludePath() .add("phar://" + depObject.getFile().getAbsolutePath().replace("\\", "/") + "/" + (includePath.startsWith("/") ? includePath.substring(1) : includePath)); } else if (action.getType() == ActionType.ACTION_EXTRACT_INCLUDE) { final String includePath = ((IActionExtractAndInclude) action).getIncludePath(); final String pharPath = ((IActionExtractAndInclude) action).getPharPath(); execConfig.getIncludePath() .add("phar://" + depObject.getFile().getAbsolutePath().replace("\\", "/") + "/" + (pharPath.startsWith("/") ? pharPath.substring(1) : pharPath) + (pharPath.endsWith("/") || pharPath.length() == 0 ? "" : "/") + (includePath.startsWith("/") ? includePath.substring(1) : includePath)); } } } } }
From source file:org.phpmaven.project.impl.ProjectPhpExecution.java
License:Apache License
/** * Adds project dependencies (/target/classes) for given scope (needed for IDE/multi-pom). * @param execConfig executable config./*from w w w. j a v a2s .co m*/ * @param project project. * @param targetScope target scope. * @throws ExpressionEvaluationException thrown on errors. * @since 2.0.1 */ private void addProjectDependencies(IPhpExecutableConfiguration execConfig, MavenProject project, final String targetScope, IDependencyConfiguration depConfig) throws ExpressionEvaluationException { final Set<Artifact> deps = project.getArtifacts(); for (final Artifact dep : deps) { if (!targetScope.equals(dep.getScope())) { continue; } boolean foundDepConfig = false; for (final IDependency depC : depConfig.getDependencies()) { if (depC.getGroupId().equals(dep.getGroupId()) && depC.getArtifactId().equals(dep.getArtifactId())) { foundDepConfig = true; } } if (foundDepConfig) { // was already be performed by addFromDepConfig() continue; } try { final MavenProject depProject = this.getProjectFromArtifact(project, dep); if (depProject.getFile() != null) { // Reference to a local project; should only happen in IDEs or multi-project poms final String depTargetDir = getClassesDirFromProject(depProject); execConfig.getIncludePath().add(depTargetDir); } } catch (ProjectBuildingException ex) { throw new ExpressionEvaluationException("Problems creating maven project from dependency", ex); } } }
From source file:org.revapi.maven.AbstractVersionModifyingMojo.java
License:Apache License
void updateProjectVersion(MavenProject project, Version version) throws MojoExecutionException { try {/* www .j av a2 s . c o m*/ VTDGen gen = new VTDGen(); gen.enableIgnoredWhiteSpace(true); gen.parseFile(project.getFile().getAbsolutePath(), true); VTDNav nav = gen.getNav(); AutoPilot ap = new AutoPilot(nav); ap.selectXPath("namespace-uri(.)"); String ns = ap.evalXPathToString(); nav.toElementNS(VTDNav.FIRST_CHILD, ns, "version"); int pos = nav.getText(); XMLModifier mod = new XMLModifier(nav); mod.updateToken(pos, version.toString()); try (OutputStream out = new FileOutputStream(project.getFile())) { mod.output(out); } } catch (IOException | ModifyException | NavException | XPathParseException | TranscodeException e) { throw new MojoExecutionException("Failed to update the version of project " + project, e); } }
From source file:org.revapi.maven.AbstractVersionModifyingMojo.java
License:Apache License
void updateProjectParentVersion(MavenProject project, Version version) throws MojoExecutionException { try {/*from www . jav a 2 s . c o m*/ VTDGen gen = new VTDGen(); gen.enableIgnoredWhiteSpace(true); gen.parseFile(project.getFile().getAbsolutePath(), true); VTDNav nav = gen.getNav(); AutoPilot ap = new AutoPilot(nav); ap.selectXPath("namespace-uri(.)"); String ns = ap.evalXPathToString(); nav.toElementNS(VTDNav.FIRST_CHILD, ns, "parent"); nav.toElementNS(VTDNav.FIRST_CHILD, ns, "version"); int pos = nav.getText(); XMLModifier mod = new XMLModifier(nav); mod.updateToken(pos, version.toString()); try (OutputStream out = new FileOutputStream(project.getFile())) { mod.output(out); } } catch (IOException | ModifyException | NavException | XPathParseException | TranscodeException e) { throw new MojoExecutionException("Failed to update the parent version of project " + project, e); } }
From source file:org.robovm.maven.plugin.AbstractRoboVMMojo.java
License:Apache License
public Config buildArchive(OS os, Arch arch, TargetType targetType) throws MojoExecutionException, MojoFailureException { getLog().info("Building RoboVM app for: " + os + " (" + arch + ")"); Config.Builder builder;//from www.j a va 2 s . com try { builder = new Config.Builder(); } catch (IOException e) { throw new MojoExecutionException(e.getMessage(), e); } // load config base file if it exists (and properties) if (propertiesFile != null) { if (!propertiesFile.exists()) { throw new MojoExecutionException( "Invalid 'propertiesFile' specified for RoboVM compile: " + propertiesFile); } try { getLog().debug( "Including properties file in RoboVM compiler config: " + propertiesFile.getAbsolutePath()); builder.addProperties(propertiesFile); } catch (IOException e) { throw new MojoExecutionException( "Failed to add properties file to RoboVM config: " + propertiesFile); } } else { File file = new File(project.getBasedir(), "robovm.properties"); if (file.exists()) { getLog().debug("Using default properties file: " + file.getAbsolutePath()); try { builder.addProperties(file); } catch (IOException e) { throw new MojoExecutionException("Failed to add properties file to RoboVM config: " + file, e); } } } if (configFile != null) { if (!configFile.exists()) { throw new MojoExecutionException( "Invalid 'configFile' specified for RoboVM compile: " + configFile); } try { getLog().debug("Loading config file for RoboVM compiler: " + configFile.getAbsolutePath()); builder.read(configFile); } catch (Exception e) { throw new MojoExecutionException("Failed to read RoboVM config file: " + configFile); } } else { File file = new File(project.getBasedir(), "robovm.xml"); if (file.exists()) { getLog().debug("Using default config file: " + file.getAbsolutePath()); try { builder.read(file); } catch (Exception e) { throw new MojoExecutionException("Failed to read RoboVM config file: " + file, e); } } } // Read embedded RoboVM <config> if there is one Plugin plugin = project.getPlugin("org.robovm:robovm-maven-plugin"); MavenProject p = project; while (p != null && plugin == null) { plugin = p.getPluginManagement().getPluginsAsMap().get("org.robovm:robovm-maven-plugin"); p = p.getParent(); } if (plugin != null) { getLog().debug("Reading RoboVM plugin configuration from " + p.getFile().getAbsolutePath()); Xpp3Dom configDom = (Xpp3Dom) plugin.getConfiguration(); if (configDom != null && configDom.getChild("config") != null) { StringWriter sw = new StringWriter(); XMLWriter xmlWriter = new PrettyPrintXMLWriter(sw, "UTF-8", null); Xpp3DomWriter.write(xmlWriter, configDom.getChild("config")); try { builder.read(new StringReader(sw.toString()), project.getBasedir()); } catch (Exception e) { throw new MojoExecutionException("Failed to read RoboVM config embedded in POM", e); } } } File tmpDir = new File(new File(installDir, os.name()), arch.name()); try { FileUtils.deleteDirectory(tmpDir); } catch (IOException e) { throw new MojoExecutionException("Failed to clean output dir " + tmpDir, e); } tmpDir.mkdirs(); builder.home(new Config.Home(unpackRoboVMDist())).logger(getRoboVMLogger()).tmpDir(tmpDir) .targetType(targetType).skipInstall(true).installDir(installDir).os(os).arch(arch); if (iosSkipSigning) { builder.iosSkipSigning(true); } else { if (iosSignIdentity != null) { getLog().debug("Using explicit iOS Signing identity: " + iosSignIdentity); builder.iosSignIdentity(SigningIdentity.find(SigningIdentity.list(), iosSignIdentity)); } if (iosProvisioningProfile != null) { getLog().debug("Using explicit iOS provisioning profile: " + iosProvisioningProfile); builder.iosProvisioningProfile( ProvisioningProfile.find(ProvisioningProfile.list(), iosProvisioningProfile)); } } builder.clearClasspathEntries(); // add JavaFX if needed if (includeJFX) { getLog().info("Including JavaFX Runtime in build"); // add jfxrt.jar from 78 backport to classpath File jfxJar = resolveJavaFXBackportRuntimeArtifact(); getLog().debug("JavaFX backport runtime JAR found at: " + jfxJar); builder.addClasspathEntry(jfxJar); // add backport compatibility additions to classpath File jfxCompatJar = resolveJavaFXBackportCompatibilityArtifact(); getLog().debug("JavaFX backport compatibilty JAR found at: " + jfxCompatJar); builder.addClasspathEntry(jfxCompatJar); // include native files as resources File iosNativesBaseDir = unpackJavaFXNativeIOSArtifact(); // builder.addLib(new File(iosNativesBaseDir, "libdecora-sse-" + // arch.getClangName() + ".a").getAbsolutePath()); builder.addLib(new Lib( new File(iosNativesBaseDir, "libglass-" + arch.getClangName() + ".a").getAbsolutePath(), true)); builder.addLib(new Lib( new File(iosNativesBaseDir, "libjavafx-font-" + arch.getClangName() + ".a").getAbsolutePath(), true)); builder.addLib(new Lib( new File(iosNativesBaseDir, "libjavafx-iio-" + arch.getClangName() + ".a").getAbsolutePath(), true)); builder.addLib(new Lib( new File(iosNativesBaseDir, "libprism-common-" + arch.getClangName() + ".a").getAbsolutePath(), true)); builder.addLib(new Lib( new File(iosNativesBaseDir, "libprism-es2-" + arch.getClangName() + ".a").getAbsolutePath(), true)); // builder.addLib(new File(iosNativesBaseDir, "libprism-sw-" + // arch.getClangName() + ".a").getAbsolutePath()); // add default 'roots' needed for JFX to work builder.addForceLinkClass("com.sun.javafx.tk.quantum.QuantumToolkit"); builder.addForceLinkClass("com.sun.prism.es2.ES2Pipeline"); builder.addForceLinkClass("com.sun.prism.es2.IOSGLFactory"); builder.addForceLinkClass("com.sun.glass.ui.ios.**.*"); builder.addForceLinkClass("javafx.scene.CssStyleHelper"); builder.addForceLinkClass("com.sun.prism.shader.**.*"); builder.addForceLinkClass("com.sun.scenario.effect.impl.es2.ES2ShaderSource"); builder.addForceLinkClass("com.sun.javafx.font.coretext.CTFactory"); builder.addForceLinkClass("sun.util.logging.PlatformLogger"); // add default 'frameworks' needed for JFX to work builder.addFramework("UIKit"); builder.addFramework("OpenGLES"); builder.addFramework("QuartzCore"); builder.addFramework("CoreGraphics"); builder.addFramework("CoreText"); builder.addFramework("ImageIO"); builder.addFramework("MobileCoreServices"); // todo do we need to exclude built-in JFX from JDK classpath? } // configure the runtime classpath try { for (Object object : project.getRuntimeClasspathElements()) { String path = (String) object; if (getLog().isDebugEnabled()) { getLog().debug("Including classpath element for RoboVM app: " + path); } builder.addClasspathEntry(new File(path)); } } catch (DependencyResolutionRequiredException e) { throw new MojoExecutionException("Error resolving application classpath for RoboVM build", e); } // execute the RoboVM build try { getLog().info("Compiling RoboVM app, this could take a while, especially the first time round"); Config config = configure(builder); AppCompiler compiler = new AppCompiler(config); compiler.compile(); return config; } catch (IOException e) { throw new MojoExecutionException("Error building RoboVM executable for app", e); } }
From source file:org.sculptor.maven.plugin.AbstractBaseMojoTestCase.java
License:Apache License
/** * Returns Mojo instance for the given goal. The Mojo instance is * initialized with a {@link MavenProject} created from the test projects in * <code>"src/test/projects/"</code> by given project name. *///w w w .ja va 2 s. com protected T createMojo(MavenProject project, String goal) throws Exception { // Create mojo @SuppressWarnings("unchecked") T mojo = (T) lookupMojo(goal, project.getFile()); assertNotNull(mojo); // Set Maven project setVariableValueToObject(mojo, "project", project); return mojo; }
From source file:org.seasar.uruma.eclipath.util.ProjectUtil.java
License:Apache License
public static File getProjectDir(MavenProject project) { File dir = project.getFile().getParentFile(); while (true) { File projectFile = new File(PathUtil.normalizePath(dir.getAbsolutePath()) + "/" + DOT_PROJECT_FILENAME); if (projectFile.exists()) { return dir; } else {//from w ww .j a v a 2s .c o m dir = dir.getParentFile(); if (dir == null) { throw new PluginRuntimeException("eclipse project directory is not found."); } } } }
From source file:org.seasar.uruma.eclipath.util.ProjectUtil.java
License:Apache License
/** * Returns eclipse workspace directory. First, this method determine the * eclipse workspace directory from pom.xml's directory. Second, determines * from "eclipse.workspace" property key which defined in the pom.xml or * settinegs.xml. If, this method can't find the workspace directory, * returns {@code null}./*from w w w . j a va 2s . c om*/ * * @param project * Maven project * @return workspace directory, or {@code null} */ public static File getWorkspaceDir(MavenProject project) { // TODO Dealing with multi projects. File workspaceDir = project.getFile().getParentFile().getParentFile(); if (isValidWorkspaceLocation(workspaceDir)) { return workspaceDir; } else { String prop = project.getProperties().getProperty(PROP_KEY_ECLIPSE_WORKSPACE); if (prop != null) { workspaceDir = new File(prop); if (isValidWorkspaceLocation(workspaceDir)) { return workspaceDir; } } Logger.warn("Can't find eclipse workspace."); return null; } }
From source file:org.sonar.batch.maven.DefaultMavenPluginExecutor.java
License:Open Source License
public void concreteExecuteMaven3(MavenProject pom, String goal) { MavenSession projectSession = mavenSession.clone(); projectSession.setCurrentProject(pom); projectSession.setProjects(Arrays.asList(pom)); projectSession.getRequest().setRecursive(false); projectSession.getRequest().setPom(pom.getFile()); projectSession.getRequest().setGoals(Arrays.asList(goal)); projectSession.getRequest().setInteractiveMode(false); lifecycleExecutor.execute(projectSession); if (projectSession.getResult().hasExceptions()) { throw new SonarException("Exception during execution of " + goal); }/*from w w w. ja v a2 s.com*/ }
From source file:org.sonar.batch.maven.MavenProjectConverter.java
License:Open Source License
private void configureModules(List<MavenProject> poms, Map<String, MavenProject> paths, Map<MavenProject, ProjectDefinition> defs) throws IOException { for (MavenProject pom : poms) { paths.put(pom.getFile().getCanonicalPath(), pom); ProjectDefinition def = ProjectDefinition.create(); merge(pom, def);/*w w w. j a v a2s .com*/ defs.put(pom, def); } }