List of usage examples for org.apache.maven.project MavenProject getBasedir
public File getBasedir()
From source file:org.gephi.maven.ScreenshotUtils.java
License:Apache License
protected static List<Image> copyScreenshots(MavenProject mavenProject, File outputFolder, String urlPrefix, Log log) throws MojoExecutionException { File folder = new File(mavenProject.getBasedir(), "src/img"); if (folder.exists()) { log.debug("Folder '" + folder.getAbsolutePath() + "' exists"); // List images in folder File[] files = folder.listFiles(new FilenameFilter() { @Override/*from w w w .j a va2 s .co m*/ public boolean accept(File dir, String name) { return !name.startsWith(".") && (name.endsWith(".png") || name.endsWith(".jpg") || name.endsWith(".jpeg") || name.endsWith(".gif")) && !name.contains(THUMBNAIL_SUFFIX); } }); // Sort files alphabetically Arrays.sort(files, new Comparator<File>() { @Override public int compare(File f1, File f2) { return f1.getName().compareTo(f2.getName()); } }); log.debug(files.length + " images found in source folder"); // Create dest folder if (outputFolder.mkdirs()) { log.debug("Output folder '" + outputFolder.getAbsolutePath() + "' was created"); } List<Image> images = new ArrayList<Image>(); for (File file : files) { if (file.getName().contains(" ")) { throw new MojoExecutionException("Image file '" + file.getAbsolutePath() + "' contains spaces. Please rename image and try again"); } // Read original file and copy to dest folder String fileName = file.getName().substring(0, file.getName().lastIndexOf(".")) + ".png"; File imageDestFile = new File(outputFolder, fileName); try { Thumbnails.of(file).outputFormat("png").outputQuality(0.90).resizer(Resizers.NULL).scale(1.0) .toFile(imageDestFile); } catch (IOException ex) { log.error("Can't copy image file from '" + file.getAbsolutePath() + "' to '" + imageDestFile.getAbsolutePath() + "'", ex); } Image image = new Image(); image.image = urlPrefix + fileName; images.add(image); // Thumbnail path String thumFileName = file.getName().substring(0, file.getName().lastIndexOf(".")) + THUMBNAIL_SUFFIX + ".png"; File thumbFile = new File(outputFolder, thumFileName); if (!thumbFile.exists()) { // Thumbnail creation try { Thumbnails.of(file).outputFormat("png").outputQuality(0.90).size(140, 140) .crop(Positions.CENTER).toFile(thumbFile); log.debug("Created thumbnail in file '" + thumbFile.getAbsolutePath() + "'"); image.thumbnail = urlPrefix + thumFileName; } catch (IOException ex) { log.error("Can't create thumbnail for image file '" + file.getAbsolutePath() + "'", ex); } } log.info("Attached image '" + file.getName() + "' to plugin " + mavenProject.getName()); } return images; } else { log.debug("Folder '" + folder.getAbsolutePath() + "' was not found"); } return null; }
From source file:org.hsc.novelSpider.bundleplugin.BundlePlugin.java
License:Apache License
protected void addMavenInstructions(MavenProject currentProject, Builder builder) throws Exception { if (currentProject.getBasedir() != null) { // update BND instructions to add included Maven resources includeMavenResources(currentProject, builder, getLog()); // calculate default export/private settings based on sources addLocalPackages(outputDirectory, builder); // tell BND where the current project source resides addMavenSourcePath(currentProject, builder, getLog()); }//from w w w.j av a 2 s . co m // update BND instructions to embed selected Maven dependencies Collection<Artifact> embeddableArtifacts = getEmbeddableArtifacts(currentProject, builder); new DependencyEmbedder(getLog(), embeddableArtifacts).processHeaders(builder); if (dumpInstructions != null) { StringBuilder buf = new StringBuilder(); getLog().debug("BND Instructions:" + NL + dumpInstructions(builder.getProperties(), buf)); if (dumpInstructions != null) { getLog().info("Writing BND instructions to " + dumpInstructions); dumpInstructions.getParentFile().mkdirs(); FileUtils.fileWrite(dumpInstructions, "# BND instructions" + NL + buf); } } if (dumpClasspath != null) { StringBuilder buf = new StringBuilder(); getLog().debug("BND Classpath:" + NL + dumpClasspath(builder.getClasspath(), buf)); if (dumpClasspath != null) { getLog().info("Writing BND classpath to " + dumpClasspath); dumpClasspath.getParentFile().mkdirs(); FileUtils.fileWrite(dumpClasspath, "# BND classpath" + NL + buf); } } List<String> errors = builder.getErrors(); if (null != errors && errors.size() > 0) { for (String str : errors) { getLog().info("" + str); } } List<String> warns = builder.getWarnings(); if (null != warns && warns.size() > 0) { for (String str : warns) { getLog().info("" + str); } } }
From source file:org.hsc.novelSpider.bundleplugin.BundlePlugin.java
License:Apache License
protected void mergeMavenManifest(MavenProject currentProject, Builder builder) throws Exception { Jar jar = builder.getJar();//from w w w. ja v a 2 s .c om if (getLog().isDebugEnabled()) { getLog().debug("BND Manifest:" + NL + dumpManifest(jar.getManifest(), new StringBuilder())); } boolean addMavenDescriptor = currentProject.getBasedir() != null; try { /* * Grab customized manifest entries from the maven-jar-plugin configuration */ MavenArchiveConfiguration archiveConfig = JarPluginConfiguration .getArchiveConfiguration(currentProject); String mavenManifestText = new MavenArchiver().getManifest(currentProject, archiveConfig).toString(); addMavenDescriptor = addMavenDescriptor && archiveConfig.isAddMavenDescriptor(); Manifest mavenManifest = new Manifest(); // First grab the external manifest file (if specified and different to target location) File externalManifestFile = archiveConfig.getManifestFile(); if (null != externalManifestFile && externalManifestFile.exists() && !externalManifestFile.equals(new File(manifestLocation, "MANIFEST.MF"))) { InputStream mis = new FileInputStream(externalManifestFile); mavenManifest.read(mis); mis.close(); } // Then apply customized entries from the jar plugin; note: manifest encoding is UTF8 mavenManifest.read(new ByteArrayInputStream(mavenManifestText.getBytes("UTF8"))); if (!archiveConfig.isManifestSectionsEmpty()) { /* * Add customized manifest sections (for some reason MavenArchiver doesn't do this for us) */ List<ManifestSection> sections = archiveConfig.getManifestSections(); for (Iterator<ManifestSection> i = sections.iterator(); i.hasNext();) { ManifestSection section = (ManifestSection) i.next(); Attributes attributes = new Attributes(); if (!section.isManifestEntriesEmpty()) { Map<String, String> entries = section.getManifestEntries(); for (Iterator<Map.Entry<String, String>> j = entries.entrySet().iterator(); j.hasNext();) { Map.Entry<String, String> entry = j.next(); attributes.putValue(entry.getKey(), entry.getValue()); } } mavenManifest.getEntries().put(section.getName(), attributes); } } Attributes mainMavenAttributes = mavenManifest.getMainAttributes(); mainMavenAttributes.putValue("Created-By", "novelSpide Maven osgi Plugin"); String[] removeHeaders = builder.getProperty(Constants.REMOVEHEADERS, "").split(","); // apply -removeheaders to the custom manifest for (int i = 0; i < removeHeaders.length; i++) { for (Iterator j = mainMavenAttributes.keySet().iterator(); j.hasNext();) { if (j.next().toString().matches(removeHeaders[i].trim())) { j.remove(); } } } /* * Overlay generated bundle manifest with customized entries */ Manifest bundleManifest = jar.getManifest(); bundleManifest.getMainAttributes().putAll(mainMavenAttributes); bundleManifest.getEntries().putAll(mavenManifest.getEntries()); jar.setManifest(bundleManifest); if (null != instructions.get("Import-Package")) { bundleManifest.getMainAttributes().putValue("Import-Package", instructions.get("Import-Package")); } if (null != instructions.get("Export-Package")) { bundleManifest.getMainAttributes().putValue("Export-Package", instructions.get("Export-Package")); } getLog().info( "hsc info Import-Package:" + bundleManifest.getMainAttributes().getValue("Import-Package")); getLog().info( "hsc info Export-Package:" + bundleManifest.getMainAttributes().getValue("Export-Package")); // adjust the import package attributes so that optional dependencies use // optional resolution. // String importPackages = bundleManifest.getMainAttributes().getValue( "Import-Package" ); // if ( importPackages != null ){ // Set<String> optionalPackages = getOptionalPackages( currentProject ); // //// Map<String, Map<String, String>> values = new Analyzer().parseHeader( importPackages ); // // Parameters params= new Analyzer().parseHeader( importPackages ); // // for ( String pkg: params.keySet() ) // { //// String pkg = entry.getKey(); // Map<String, String> options = params.get(pkg); // if ( !options.containsKey( "resolution:" ) && optionalPackages.contains( pkg ) ) // { // options.put( "resolution:", "optional" ); // } // } // String result = Processor.printClauses( params ); // getLog().info("hsc info replace Import-Package:"+bundleManifest.getMainAttributes().getValue( "Import-Package" )); // // bundleManifest.getMainAttributes().putValue( "Import-Package", result ); // } // jar.setManifest( bundleManifest ); } catch (Exception e) { getLog().warn("Unable to merge Maven manifest: " + e.getLocalizedMessage()); } if (addMavenDescriptor) { doMavenMetadata(currentProject, jar); } getLog().debug("Final Manifest:" + NL + dumpManifest(jar.getManifest(), new StringBuilder())); builder.setJar(jar); }
From source file:org.hsc.novelSpider.bundleplugin.BundlePlugin.java
License:Apache License
/** * @param jar/*from ww w. j ava2 s.c o m*/ * @throws IOException */ private void doMavenMetadata(MavenProject currentProject, Jar jar) throws IOException { String path = "META-INF/maven/" + currentProject.getGroupId() + "/" + currentProject.getArtifactId(); File pomFile = new File(currentProject.getBasedir(), "pom.xml"); jar.putResource(path + "/pom.xml", new FileResource(pomFile)); Properties p = new Properties(); p.put("version", currentProject.getVersion()); p.put("groupId", currentProject.getGroupId()); p.put("artifactId", currentProject.getArtifactId()); ByteArrayOutputStream out = new ByteArrayOutputStream(); p.store(out, "Generated by org.hsc.novelSpider.bundleplugin"); jar.putResource(path + "/pom.properties", new EmbeddedResource(out.toByteArray(), System.currentTimeMillis())); }
From source file:org.hsc.novelSpider.bundleplugin.BundlePlugin.java
License:Apache License
protected static File getBase(MavenProject currentProject) { return currentProject.getBasedir() != null ? currentProject.getBasedir() : new File(""); }
From source file:org.hsc.novelSpider.bundleplugin.BundlePlugin.java
License:Apache License
protected static String getMavenResourcePaths(MavenProject currentProject) { final String basePath = currentProject.getBasedir().getAbsolutePath(); Set<String> pathSet = new LinkedHashSet<String>(); for (Iterator<Resource> i = getMavenResources(currentProject).iterator(); i.hasNext();) { Resource resource = i.next(); final String sourcePath = resource.getDirectory(); final String targetPath = resource.getTargetPath(); // ignore empty or non-local resources if (new File(sourcePath).exists() && ((targetPath == null) || (targetPath.indexOf("..") < 0))) { DirectoryScanner scanner = new DirectoryScanner(); scanner.setBasedir(sourcePath); if (resource.getIncludes() != null && !resource.getIncludes().isEmpty()) { scanner.setIncludes((String[]) resource.getIncludes().toArray(EMPTY_STRING_ARRAY)); } else { scanner.setIncludes(DEFAULT_INCLUDES); }//w ww.j a va 2s .c o m if (resource.getExcludes() != null && !resource.getExcludes().isEmpty()) { scanner.setExcludes((String[]) resource.getExcludes().toArray(EMPTY_STRING_ARRAY)); } scanner.addDefaultExcludes(); scanner.scan(); List<String> includedFiles = Arrays.asList(scanner.getIncludedFiles()); for (Iterator<String> j = includedFiles.iterator(); j.hasNext();) { String name = j.next(); String path = sourcePath + '/' + name; // make relative to project if (path.startsWith(basePath)) { if (path.length() == basePath.length()) { path = "."; } else { path = path.substring(basePath.length() + 1); } } // replace windows backslash with a slash // this is a workaround for a problem with bnd 0.0.189 if (File.separatorChar != '/') { name = name.replace(File.separatorChar, '/'); path = path.replace(File.separatorChar, '/'); } // copy to correct place path = name + '=' + path; if (targetPath != null) { path = targetPath + '/' + path; } // use Bnd filtering? if (resource.isFiltering()) { path = '{' + path + '}'; } pathSet.add(path); } } } StringBuffer resourcePaths = new StringBuffer(); for (Iterator<String> i = pathSet.iterator(); i.hasNext();) { resourcePaths.append(i.next()); if (i.hasNext()) { resourcePaths.append(','); } } return resourcePaths.toString(); }
From source file:org.jacoco.maven.ReportAggregateMojo.java
License:Open Source License
@Override void loadExecutionData(final ReportSupport support) throws IOException { // https://issues.apache.org/jira/browse/MNG-5440 if (dataFileIncludes == null) { dataFileIncludes = Arrays.asList("target/*.exec"); }// w w w. ja v a 2 s . c o m final FileFilter filter = new FileFilter(dataFileIncludes, dataFileExcludes); loadExecutionData(support, filter, getProject().getBasedir()); for (final MavenProject dependency : findDependencies(Artifact.SCOPE_COMPILE, Artifact.SCOPE_RUNTIME, Artifact.SCOPE_PROVIDED, Artifact.SCOPE_TEST)) { loadExecutionData(support, filter, dependency.getBasedir()); } }
From source file:org.jacoco.maven.ReportSupport.java
License:Open Source License
private static File resolvePath(final MavenProject project, final String path) { File file = new File(path); if (!file.isAbsolute()) { file = new File(project.getBasedir(), path); }/*from ww w. j a va2 s. com*/ return file; }
From source file:org.jahia.utils.maven.plugin.osgi.DependenciesMojo.java
License:Open Source License
protected void resolveEmbeddedDependencies(MavenProject currentProject, Builder builder) throws Exception { if (currentProject.getBasedir() != null) { // update BND instructions to add included Maven resources includeMavenResources(currentProject, builder, getLog()); // calculate default export/private settings based on sources addLocalPackages(new File(projectOutputDirectory), builder); // tell BND where the current project source resides addMavenSourcePath(currentProject, builder, getLog()); }//from w ww. java 2 s.c o m // update BND instructions to embed selected Maven dependencies Collection<Artifact> embeddableArtifacts = getEmbeddableArtifacts(currentProject, builder); DependencyEmbedder dependencyEmbedder = new DependencyEmbedder(getLog(), embeddableArtifacts); dependencyEmbedder.processHeaders(builder); inlinedPaths = dependencyEmbedder.getInlinedPaths(); embeddedArtifacts = dependencyEmbedder.getEmbeddedArtifacts(); }
From source file:org.jasig.maven.legal.util.ResourceFinder.java
License:Apache License
private URL searchProjectTree(MavenProject project, String resource) { // first search relatively to the base directory URL res = toURL(new File(project.getBasedir(), resource)); if (res != null) { return res; }/*from w w w . j a v a2s .co m*/ //Look up the project tree to try and find a match as well. final MavenProject parent = project.getParent(); if (!project.isExecutionRoot() && parent != null && parent.getBasedir() != null) { return this.searchProjectTree(parent, resource); } return null; }