List of usage examples for org.apache.maven.project MavenProject getArtifactId
public String getArtifactId()
From source file:com.github.maven_nar.NarTestMojo.java
License:Apache License
private void runExecutable(final Library library) throws MojoExecutionException, MojoFailureException { if (library.getType().equals(Library.EXECUTABLE) && library.shouldRun()) { final MavenProject project = getMavenProject(); // FIXME NAR-90, we could make sure we get the final name from layout final String extension = getOS().equals(OS.WINDOWS) ? ".exe" : ""; final File executable = new File( getLayout().getBinDirectory(getTargetDirectory(), getMavenProject().getArtifactId(), getMavenProject().getVersion(), getAOL().toString()), project.getArtifactId() + extension); if (!executable.exists()) { getLog().warn("Skipping non-existing executable " + executable); return; }/*from w w w. ja va2 s . co m*/ getLog().info("Running executable " + executable); final List args = library.getArgs(); final int result = NarUtil.runCommand(executable.getPath(), (String[]) args.toArray(new String[args.size()]), null, generateEnvironment(), getLog()); if (result != 0) { throw new MojoFailureException("Test " + executable + " failed with exit code: " + result + " 0x" + Integer.toHexString(result)); } } }
From source file:com.github.spyhunter99.jacoco.report.plugin.JacocoReport.java
License:Apache License
private List<JacocoItem> copyResources(MavenProject project) throws IOException { if (project == null) { return Collections.EMPTY_LIST; }/*www. ja v a 2 s . c om*/ List<JacocoItem> outDirs = new ArrayList<>(); if ("pom".equalsIgnoreCase(project.getPackaging())) { for (int k = 0; k < project.getCollectedProjects().size(); k++) { outDirs.addAll(copyResources((MavenProject) project.getCollectedProjects().get(k))); } } else { File moduleBaseDir = project.getBasedir(); File target = new File(moduleBaseDir, "target"); if (target.exists()) { File jacocoUt = new File(moduleBaseDir, "target/site/jacoco-ut/"); //TODO properterize File jacocoIt = new File(moduleBaseDir, "target/site/jacoco-it/"); //TODO properterize JacocoItem item = new JacocoItem(); item.setModuleName(project.getArtifactId()); if (jacocoIt.exists()) { //since all artifacts should have unique names...this should be ok JacocoReportMetric report = new JacocoReportMetric(); report.setReportDir(jacocoIt); report.setMetric(getMetric(new File(jacocoIt, "index.html"))); item.getReportDirs().add(report); File dest = new File( "target/site/jacoco/" + project.getArtifactId() + "/" + jacocoIt.getName()); dest.mkdirs(); org.apache.commons.io.FileUtils.copyDirectory(jacocoIt, dest); } if (jacocoUt.exists()) { //since all artifacts should have unique names...this should be ok JacocoReportMetric report = new JacocoReportMetric(); report.setReportDir(jacocoUt); report.setMetric(getMetric(new File(jacocoUt, "index.html"))); item.getReportDirs().add(report); File dest = new File( "target/site/jacoco/" + project.getArtifactId() + "/" + jacocoUt.getName()); dest.mkdirs(); org.apache.commons.io.FileUtils.copyDirectory(jacocoUt, dest); } outDirs.add(item); } } return outDirs; }
From source file:com.github.zhve.ideaplugin.IdeaCleanMojo.java
License:Apache License
@Override public void execute() throws MojoExecutionException, MojoFailureException { getLog().info("Delete Workspace Files:"); for (MavenProject project : reactorProjects) { Util.deleteFileOrDirectory(getLog(), new File(project.getBasedir(), project.getArtifactId() + ".iml")); if (project.isExecutionRoot()) { Util.deleteFileOrDirectory(getLog(), new File(project.getBasedir(), ".idea")); Util.deleteFileOrDirectory(getLog(), new File(project.getBasedir(), project.getArtifactId() + ".ipr")); Util.deleteFileOrDirectory(getLog(), new File(project.getBasedir(), project.getArtifactId() + ".iws")); }/* w ww.j av a 2 s .co m*/ } }
From source file:com.github.zhve.ideaplugin.IdeaPluginMojo.java
License:Apache License
protected void doExecute() throws Exception { // prepare/* w w w .ja va 2 s. co m*/ ArtifactHolder artifactHolder = getArtifactHolder(); VelocityWorker velocityWorker = getVelocityWorker(); VelocityContext context = new VelocityContext(); MavenProject project = getProject(); // fill iml-attributes String buildDirectory = project.getBuild().getDirectory(); String standardBuildDirectory = project.getFile().getParent() + File.separator + "target"; context.put("buildDirectory", buildDirectory.startsWith(standardBuildDirectory) ? standardBuildDirectory : buildDirectory); context.put("context", this); context.put("gaeHome", gaeHome == null ? null : new File(gaeHome).getCanonicalPath()); context.put("MD", "$MODULE_DIR$"); context.put("packagingPom", "pom".equals(project.getPackaging())); context.put("packagingWar", "war".equals(project.getPackaging())); context.put("project", project); // generate iml file createFile(context, velocityWorker.getImlTemplate(), "iml"); // for non execution root just exit if (!getProject().isExecutionRoot()) return; // fill ipr-attributes context.put("M", getLocalRepositoryBasePath()); context.put("assembleModulesIntoJars", assembleModulesIntoJars); context.put("jdkName", jdkName); context.put("jdkLevel", jdkLevel); context.put("wildcardResourcePatterns", Util.escapeXmlAttribute(wildcardResourcePatterns)); List<MavenProject> warProjects = artifactHolder.getProjectsWithPackaging("war"); // check id uniques Set<String> used = new HashSet<String>(); for (MavenProject item : warProjects) if (!used.add(item.getArtifactId())) throw new MojoExecutionException( "Two or more war-packagins projects in reactor have the same artifactId, please make sure that <artifactId> is unique for each war-packagins project."); Collections.sort(warProjects, ProjectComparator.INSTANCE); context.put("warProjects", warProjects); IssueManagement issueManagement = getProject().getIssueManagement(); if (issueManagement != null) { String system = issueManagement.getSystem(); String url = issueManagement.getUrl(); if ("Redmine".equalsIgnoreCase(system)) { context.put("issueNavigationExist", Boolean.TRUE); context.put("issueRegexp", "\\d+"); context.put("linkRegexp", url + "/issues/$0"); } else if ("JIRA".equalsIgnoreCase(system)) { context.put("issueNavigationExist", Boolean.TRUE); context.put("issueRegexp", "[A-Z]+\\-\\d+"); context.put("linkRegexp", url + "/browse/$0"); } else if ("YouTrack".equalsIgnoreCase(system)) { context.put("issueNavigationExist", Boolean.TRUE); context.put("issueRegexp", "[A-Z]+\\-\\d+"); context.put("linkRegexp", url + "/issue/$0"); } else if ("Google Code".equalsIgnoreCase(system)) { context.put("issueNavigationExist", Boolean.TRUE); context.put("issueRegexp", "\\d+"); context.put("linkRegexp", url + "/issues/detail?id=$0"); } else if ("GitHub".equalsIgnoreCase(system)) { context.put("issueNavigationExist", Boolean.TRUE); context.put("issueRegexp", "\\d+"); context.put("linkRegexp", url + "/$0"); } } createFile(context, velocityWorker.getIprTemplate(), "ipr"); // fill iws-attributes context.put("compileInBackground", compileInBackground); context.put("assertNotNull", assertNotNull); context.put("hideEmptyPackages", hideEmptyPackages); context.put("autoscrollToSource", autoscrollToSource); context.put("autoscrollFromSource", autoscrollFromSource); context.put("sortByType", sortByType); context.put("optimizeImportsBeforeCommit", optimizeImportsBeforeCommit); context.put("reformatCodeBeforeCommit", reformatCodeBeforeCommit); context.put("performCodeAnalysisBeforeCommit", performCodeAnalysisBeforeCommit); if (!warProjects.isEmpty()) { // fill war-attributes MavenProject warProject = getDefaultWarProject(warProjects); context.put("warProject", warProject); warProjects.remove(warProject); context.put("otherWarProjects", warProjects); context.put("applicationServerTitle", StringUtils.isEmpty(applicationServerTitle) ? warProject.getArtifactId() : Util.escapeXmlAttribute(applicationServerTitle)); context.put("applicationServerName", gaeHome == null ? applicationServerName : "Google AppEngine Dev"); context.put("applicationServerVersion", applicationServerVersion); context.put("openInBrowser", openInBrowser); context.put("openInBrowserUrl", Util.escapeXmlAttribute(openInBrowserUrl)); context.put("vmParameters", vmParameters == null ? "" : Util.escapeXmlAttribute(vmParameters)); context.put("deploymentContextPath", deploymentContextPath); if (gaeHome != null) { context.put("applicationServerConfigurationType", "GoogleAppEngineDevServer"); context.put("applicationServerFullName", applicationServerFullName == null ? "AppEngine Dev" : applicationServerFullName); } else if ("Tomcat".equals(applicationServerName)) { context.put("applicationServerConfigurationType", "#com.intellij.j2ee.web.tomcat.TomcatRunConfigurationFactory"); context.put("applicationServerFullName", applicationServerFullName == null ? applicationServerName + " " + applicationServerVersion : applicationServerFullName); } else if ("Jetty".equals(applicationServerName)) { context.put("applicationServerConfigurationType", "org.codebrewer.idea.jetty.JettyRunConfigurationType"); context.put("applicationServerFullName", applicationServerFullName == null ? applicationServerName + " " + applicationServerVersion : applicationServerFullName); } else throw new MojoExecutionException("Unknown applicationServerName: " + applicationServerName + ", possible values: Tomcat, Jetty"); } createFile(context, velocityWorker.getIwsTemplate(), "iws"); File idea = new File(project.getBasedir(), ".idea"); if (idea.exists()) { getLog().info(""); getLog().info("Delete Workspace Files:"); getLog().info(""); Util.deleteFileOrDirectory(getLog(), idea); } }
From source file:com.github.zhve.ideaplugin.IdeaPluginMojoBase.java
License:Apache License
public List<String> getReactorPaths() { List<String> list = new ArrayList<String>(); list.add(new File(project.getFile().getParentFile(), project.getArtifactId() + ".iml").getAbsolutePath()); for (Object collectedProject : project.getCollectedProjects()) { MavenProject reactorProject = (MavenProject) collectedProject; list.add(new File(reactorProject.getFile().getParentFile(), reactorProject.getArtifactId() + ".iml") .getAbsolutePath());/*from ww w .j ava 2 s.c o m*/ } return list; }
From source file:com.github.zhve.ideaplugin.ProjectComparator.java
License:Apache License
@Override public int compare(MavenProject o1, MavenProject o2) { return o1.getArtifactId().compareTo(o2.getArtifactId()); }
From source file:com.google.gdt.eclipse.maven.configurators.MavenProjectConfigurator.java
License:Open Source License
/** * Save the settings for the GWT nature in the application GWT preferences. * * @param project/*from www.j a v a2 s .co m*/ * @param mavenProject * @param mavenConfig * @throws BackingStoreException */ private void persistGwtNatureSettings(IProject project, MavenProject mavenProject, Xpp3Dom mavenConfig) throws BackingStoreException { IPath warOutDir = getWarOutDir(project, mavenProject); WebAppProjectProperties.setWarSrcDir(project, getWarSrcDir(mavenProject, mavenConfig)); // src/main/webapp WebAppProjectProperties.setWarSrcDirIsOutput(project, getLaunchFromHere(mavenConfig)); // false // TODO the extension should be used, from WarArgProcessor WebAppProjectProperties.setLastUsedWarOutLocation(project, warOutDir); WebAppProjectProperties.setGwtMavenModuleName(project, getGwtModuleName(mavenProject)); WebAppProjectProperties.setGwtMavenModuleShortName(project, getGwtModuleShortName(mavenProject)); String message = "MavenProjectConfiguratior Maven: Success with setting up GWT Nature\n"; message += "\tartifactId=" + mavenProject.getArtifactId() + "\n"; message += "\tversion=" + mavenProject.getVersion() + "\n"; message += "\twarOutDir=" + warOutDir; Activator.log(message); }
From source file:com.google.gdt.eclipse.maven.configurators.MavenProjectConfigurator.java
License:Open Source License
/** * Get the war output directory.//from w w w . ja v a 2 s.c om * * @param project * @param mavenProject * @return returns the war output path */ private IPath getWarOutDir(IProject project, MavenProject mavenProject) { String artifactId = mavenProject.getArtifactId(); String version = mavenProject.getVersion(); IPath locationOfProject = (project.getRawLocation() != null ? project.getRawLocation() : project.getLocation()); IPath warOut = null; // Default directory target/artifact-version if (locationOfProject != null && artifactId != null && version != null) { warOut = locationOfProject.append("target").append(artifactId + "-" + version); } // Get the GWT Maven plugin 1 <hostedWebapp/> directory if (isGwtMavenPlugin1(mavenProject) && getGwtMavenPluginHostedWebAppDirectory(mavenProject) != null) { warOut = getGwtMavenPluginHostedWebAppDirectory(mavenProject); } // Get the Gwt Maven plugin 1 <webappDirectory/> if (isGwtMavenPlugin2(mavenProject) && getGwtPlugin2WebAppDirectory(mavenProject) != null) { warOut = getGwtPlugin2WebAppDirectory(mavenProject); } // Get the maven war plugin <webappDirectory/> if (getMavenWarPluginWebAppDirectory(mavenProject) != null) { warOut = getMavenWarPluginWebAppDirectory(mavenProject); } // make the directory if it doesn't exist if (warOut != null) { warOut.toFile().mkdirs(); } return warOut; }
From source file:com.google.gdt.eclipse.maven.e35.configurators.GoogleProjectConfigurator.java
License:Open Source License
@Override protected void doConfigure(final MavenProject mavenProject, IProject project, ProjectConfigurationRequest request, final IProgressMonitor monitor) throws CoreException { final IMaven maven = MavenPlugin.getDefault().getMaven(); boolean configureGaeNatureSuccess = configureNature(project, mavenProject, GaeNature.NATURE_ID, true, new NatureCallbackAdapter() { @Override/*from w ww . java 2s . c o m*/ public void beforeAddingNature() { try { DefaultMavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest(); executionRequest.setBaseDirectory(mavenProject.getBasedir()); executionRequest.setLocalRepository(maven.getLocalRepository()); executionRequest.setRemoteRepositories(mavenProject.getRemoteArtifactRepositories()); executionRequest .setPluginArtifactRepositories(mavenProject.getPluginArtifactRepositories()); executionRequest.setPom(mavenProject.getFile()); executionRequest.setGoals(GAE_UNPACK_GOAL); MavenExecutionResult result = maven.execute(executionRequest, monitor); if (result.hasExceptions()) { Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error configuring project", result.getExceptions().get(0))); } } catch (CoreException e) { Activator.getDefault().getLog().log( new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error configuring project", e)); } } }, monitor); boolean configureGWTNatureSuccess = configureNature(project, mavenProject, GWTNature.NATURE_ID, true, new NatureCallbackAdapter() { @Override public void beforeAddingNature() { // Get the GWT version from the project pom String gwtVersion = null; List<Dependency> dependencies = mavenProject.getDependencies(); for (Dependency dependency : dependencies) { if (GWTMavenRuntime.MAVEN_GWT_GROUP_ID.equals(dependency.getGroupId()) && (GWTMavenRuntime.MAVEN_GWT_USER_ARTIFACT_ID .equals(dependency.getArtifactId()) || GWTMavenRuntime.MAVEN_GWT_SERVLET_ARTIFACT_ID .equals(dependency.getArtifactId()))) { gwtVersion = dependency.getVersion(); break; } } // Check that the pom.xml has GWT dependencies if (!StringUtilities.isEmpty(gwtVersion)) { try { /* * Download and install the gwt-dev.jar into the local * repository. */ maven.resolve(GWTMavenRuntime.MAVEN_GWT_GROUP_ID, GWTMavenRuntime.MAVEN_GWT_DEV_JAR_ARTIFACT_ID, gwtVersion, "jar", null, mavenProject.getRemoteArtifactRepositories(), monitor); } catch (CoreException e) { Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error configuring project", e)); } } } }, monitor); if (configureGWTNatureSuccess || configureGaeNatureSuccess) { try { // Add GWT Web Application configuration parameters WebAppProjectProperties.setWarSrcDir(project, new Path("src/main/webapp")); WebAppProjectProperties.setWarSrcDirIsOutput(project, false); String artifactId = mavenProject.getArtifactId(); String version = mavenProject.getVersion(); IPath location = (project.getRawLocation() != null ? project.getRawLocation() : project.getLocation()); if (location != null && artifactId != null && version != null) { WebAppProjectProperties.setLastUsedWarOutLocation(project, location.append("target").append(artifactId + "-" + version)); } } catch (BackingStoreException be) { Activator.getDefault().getLog() .log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error configuring project", be)); } } }
From source file:com.googlecode.bdoc.mojo.RootPackageGenerator.java
License:Open Source License
public static String calculateRootPackage(MavenProject project) { String groupId = project.getGroupId(); String artifactId = project.getArtifactId(); String result = null;//from www. j av a 2s . c o m if (groupId.equals(artifactId) || groupId.endsWith(artifactId)) { result = groupId; } else { String[] groupIdPices = groupId.split("\\."); if (1 == groupIdPices.length) { groupIdPices = groupId.split("-"); } if (0 < groupIdPices.length) { String groupIdPostfix = groupIdPices[groupIdPices.length - 1]; String[] artifactIdPices = artifactId.split("-"); String artifactIdPrefix = artifactIdPices[0]; if (groupIdPostfix.equals(artifactIdPrefix)) { result = groupId + artifactId.substring(artifactIdPrefix.length()); } } } if (null == result) { result = groupId; } return result.replace('-', '.'); }