List of usage examples for org.apache.maven.project MavenProject getBasedir
public File getBasedir()
From source file:net.roboconf.maven.ValidateApplicationMojo.java
License:Apache License
/** * Validate aspects that are specific to recipes (i.e. partial Roboconf applications). * <p>//from w w w . j av a2 s . c om * Most of this validation could have been handled through enforcer rules. However, * they are all warnings and we do not want to create hundreds of projects. We can * see these rules as good practices that will be shared amongst all the Roboonf users. * </p> * <p> * At worst, users can ignore these warnings. * Or they can submit a feature request to add or remove validation rules. * </p> * * @param project a Maven project * @param tpl an application template * @param official true if this recipe is maintained by the Roboconf team, false otherwise * @return a non-null list of errors */ static Collection<RoboconfError> validateRecipesSpecifics(MavenProject project, ApplicationTemplate tpl, boolean official) { Collection<RoboconfError> result = new ArrayList<>(); if (!project.getArtifactId().equals(project.getArtifactId().toLowerCase())) result.add(new RoboconfError(ErrorCode.REC_ARTIFACT_ID_IN_LOWER_CASE)); if (!tpl.getRootInstances().isEmpty()) result.add(new RoboconfError(ErrorCode.REC_AVOID_INSTANCES)); if (official && !Constants.OFFICIAL_RECIPES_GROUP_ID.equals(project.getGroupId())) result.add(new RoboconfError(ErrorCode.REC_OFFICIAL_GROUP_ID)); if (!project.getArtifactId().equals(project.getArtifactId())) result.add(new RoboconfError(ErrorCode.REC_NON_MATCHING_ARTIFACT_ID)); File[] files = project.getBasedir().listFiles(); boolean found = false; if (files != null) { for (int i = 0; i < files.length && !found; i++) found = files[i].getName().matches("(?i)readme(\\..*)?"); } if (!found) result.add(new RoboconfError(ErrorCode.REC_MISSING_README)); return result; }
From source file:net.ubos.tools.pacmanpkgmavenplugin.PacmanPkgMavenPlugin.java
License:Open Source License
/** * {@inheritDoc}// w ww . j a v a 2s. c o m * * @throws MojoExecutionException */ @Override public void execute() throws MojoExecutionException { MavenProject project = (MavenProject) getPluginContext().get("project"); String packaging = project.getPackaging(); if (!"jar".equals(packaging) && !"ear".equals(packaging) && !"war".equals(packaging)) { return; } getLog().info("Generating PKGBUILD @ " + project.getName()); // pull stuff out of MavenProject String artifactId = project.getArtifactId(); String version = project.getVersion(); String url = project.getUrl(); String description = project.getDescription(); Set<Artifact> dependencies = project.getDependencyArtifacts(); File artifactFile = project.getArtifact().getFile(); if (artifactFile == null || !artifactFile.exists()) { throw new MojoExecutionException("pacmanpkg must be executed as part of a build, not standalone," + " otherwise it can't find the main JAR file"); } // translate to PKGBUILD fields String pkgname = artifactId; String pkgver = version.replaceAll("-SNAPSHOT", "a"); // alpha String pkgdesc = "A Java package available on UBOS"; if (description != null) { if (description.length() > 64) { pkgdesc = description.substring(0, 64) + "..."; } else { pkgdesc = description; } } ArrayList<String> depends = new ArrayList<>(dependencies.size()); for (Artifact a : dependencies) { if (!"test".equals(a.getScope())) { depends.add(a.getArtifactId()); } } // write to PKGBUILD try { File baseDir = project.getBasedir(); File pkgBuild = new File(baseDir, "target/PKGBUILD"); PrintWriter out = new PrintWriter(pkgBuild); getLog().debug("Writing PKGBUILD to " + pkgBuild.getAbsolutePath()); out.println("#"); out.println(" * Automatically generated by pacman-pkg-maven-plugin; do not modify."); out.println("#"); out.println(); out.println("pkgname=" + pkgname); out.println("pkgver=" + pkgver); out.println("pkgrel=" + pkgrel); out.println("pkgdesc='" + pkgdesc + "'"); out.println("arch=('any')"); out.println("url='" + url + "'"); out.println("license=('" + license + "')"); out.print("depends=("); String sep = ""; for (String d : depends) { out.print(sep); sep = ","; out.print("'"); out.print(d); out.print("'"); } out.println(")"); out.println(); out.println("package() ("); out.println(" mkdir -p ${pkgdir}/usr/share/java"); out.println(" install -m644 ${startdir}/" + artifactFile.getName() + " ${pkgdir}/usr/share/java/"); out.println(")"); out.close(); } catch (IOException ex) { throw new MojoExecutionException("Failed to write target/PKGBUILD", ex); } }
From source file:nl.mpi.tla.version.controller.VersionControlCheck.java
License:Open Source License
@Override public void execute() throws MojoExecutionException { final VcsVersionChecker versionChecker; try {// ww w .j ava2 s . c om switch (VcsType.valueOf(vcsType)) { case git: versionChecker = new GitVersionChecker(new CommandRunnerImpl()); break; case svn: versionChecker = new SvnVersionChecker(new CommandRunnerImpl()); break; default: throw new MojoExecutionException("Unknown version control system: " + vcsType); } } catch (IllegalArgumentException exception) { throw new MojoExecutionException("Unknown version control system: " + vcsType + "\nValid options are: " + VcsType.git.name() + " or " + VcsType.svn.name()); } if (verbose) { logger.info("VersionControlCheck"); logger.info("project: " + project); logger.info("majorVersion: " + majorVersion); logger.info("minorVersion: " + minorVersion); logger.info("buildType: " + buildType); logger.info("outputDirectory: " + outputDirectory); logger.info("projectDirectory :" + projectDirectory); } for (MavenProject reactorProject : mavenProjects) { final String artifactId = reactorProject.getArtifactId(); final String moduleVersion = reactorProject.getVersion(); final String groupId = reactorProject.getGroupId(); logger.info("Checking version numbers for " + artifactId); if (verbose) { logger.info("artifactId: " + artifactId); logger.info("moduleVersion: " + moduleVersion); logger.info("moduleDir :" + reactorProject.getBasedir()); } // for (MavenProject dependencyProject : reactorProject.getDependencies()) { // logger.info("dependencyProject:" + dependencyProject.getArtifactId()); // } final String expectedVersion; final String buildVersionString; final File moduleDirectory = reactorProject.getBasedir(); if (allowSnapshots && moduleVersion.contains("SNAPSHOT")) { expectedVersion = majorVersion + "." + minorVersion + "-" + buildType + "-SNAPSHOT"; buildVersionString = "-1"; //"SNAPSHOT"; it will be nice to have snapshot here but we need to update some of the unit tests first } else if ((modulesWithShortVersion != null && modulesWithShortVersion.contains(artifactId)) || (moduleWithShortVersion != null && moduleWithShortVersion.equals(artifactId))) { expectedVersion = majorVersion + "." + minorVersion; buildVersionString = "-1"; } else { logger.info("getting build number"); int buildVersion = versionChecker.getBuildNumber(verbose, moduleDirectory, "."); logger.info(artifactId + ".buildVersion: " + Integer.toString(buildVersion)); expectedVersion = majorVersion + "." + minorVersion + "." + buildVersion + "-" + buildType; buildVersionString = Integer.toString(buildVersion); } if (!expectedVersion.equals(moduleVersion)) { logger.error("Expecting version number: " + expectedVersion); logger.error("But found: " + moduleVersion); logger.error("Artifact: " + artifactId); throw new MojoExecutionException("The build numbers to not match for '" + artifactId + "': '" + expectedVersion + "' vs '" + moduleVersion + "'"); } // get the last commit date logger.info("getting lastCommitDate"); final String lastCommitDate = versionChecker.getLastCommitDate(verbose, moduleDirectory, "."); logger.info(".lastCommitDate:" + lastCommitDate); // construct the compile date DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z"); Date date = new Date(); final String buildDate = dateFormat.format(date); // setting the maven properties final String versionPropertyName = groupId + "." + artifactId + ".moduleVersion"; logger.info("Setting property '" + versionPropertyName + "' to '" + expectedVersion + "'"); reactorProject.getProperties().setProperty(versionPropertyName, expectedVersion); reactorProject.getProperties().setProperty(propertiesPrefix + ".majorVersion", majorVersion); reactorProject.getProperties().setProperty(propertiesPrefix + ".minorVersion", minorVersion); reactorProject.getProperties().setProperty(propertiesPrefix + ".buildVersion", buildVersionString); reactorProject.getProperties().setProperty(propertiesPrefix + ".lastCommitDate", lastCommitDate); reactorProject.getProperties().setProperty(propertiesPrefix + ".buildDate", buildDate); } }
From source file:npanday.assembler.impl.AssemblerContextImpl.java
License:Apache License
public AssemblyInfo getAssemblyInfo(MavenProject mavenProject) { String basedir = mavenProject.getBasedir().toString(); AssemblyInfo assemblyInfo = new AssemblyInfo(); String description = (mavenProject.getDescription() != null) ? mavenProject.getDescription() : ""; String version = (mavenProject.getVersion() != null) ? mavenProject.getVersion() : ""; String name = mavenProject.getName(); Organization org = mavenProject.getOrganization(); String company = (org != null) ? org.getName() : ""; String copyright = ""; String informationalVersion = ""; String configuration = ""; File file = new File(basedir + "/COPYRIGHT.txt"); if (file.exists()) { logger.debug("NPANDAY-020-000: Found Copyright: " + file.getAbsolutePath()); FileInputStream fis = null; try {/* ww w .j ava 2 s . c o m*/ fis = new FileInputStream(file); copyright = IOUtil.toString(fis).replace("\r", " ").replace("\n", " ").replace("\"", "'"); } catch (IOException e) { logger.info("NPANDAY-020-001: Could not get copyright: File = " + file.getAbsolutePath(), e); } finally { if (fis != null) { IOUtil.close(fis); } } } informationalVersion = version; if (version.contains("-")) { version = version.split("-")[0]; } assemblyInfo.setCompany(company); assemblyInfo.setCopyright(copyright); assemblyInfo.setCulture(""); assemblyInfo.setDescription(description); assemblyInfo.setProduct(company + "-" + name); assemblyInfo.setTitle(name); assemblyInfo.setTrademark(""); assemblyInfo.setInformationalVersion(informationalVersion); assemblyInfo.setVersion(version); assemblyInfo.setConfiguration(configuration); return assemblyInfo; }
From source file:npanday.assembler.impl.JavaAssemblyInfoMarshaller.java
License:Apache License
/** * @see AssemblyInfoMarshaller#marshal(npanday.assembler.AssemblyInfo, org.apache.maven.project.MavenProject, * java.io.OutputStream)//from w ww .j a v a 2s .co m */ public void marshal(AssemblyInfo assemblyInfo, MavenProject mavenProject, OutputStream outputStream) throws IOException { String src = mavenProject.getBasedir() + "/target/build-sources"; StringBuffer sb = new StringBuffer(); sb.append("import System.Reflection;\r\n").append("import System.Runtime.CompilerServices.*;r\n") .append(createEntry("Description", assemblyInfo.getDescription())) .append(createEntry("Title", assemblyInfo.getTitle())) .append(createEntry("Company", assemblyInfo.getCompany())) .append(createEntry("Product", assemblyInfo.getProduct())) .append(createEntry("Copyright", assemblyInfo.getCopyright().replace("\"", "\\"))) .append(createEntry("Trademark", assemblyInfo.getTrademark())) .append(createEntry("Culture", assemblyInfo.getCulture())) .append(createEntry("Version", assemblyInfo.getVersion())) .append(createEntry("Configuration", assemblyInfo.getConfiguration())); FileOutputStream man = null; try { String groupIdAsDir = mavenProject.getGroupId().replace(".", File.separator); File file = new File(src + "/META-INF/" + groupIdAsDir); file.mkdirs(); man = new FileOutputStream( src + "/META-INF/" + groupIdAsDir + File.separator + "AssemblyInfo." + plugin.getExtension()); man.write(sb.toString().getBytes()); } catch (IOException e) { throw new IOException(); } finally { if (man != null) { man.close(); } } }
From source file:npanday.assembler.impl.VBAssemblyInfoMarshaller.java
License:Apache License
/** * @see AssemblyInfoMarshaller#marshal(npanday.assembler.AssemblyInfo, org.apache.maven.project.MavenProject, * java.io.OutputStream)/*from w w w. j a v a 2 s . co m*/ */ public void marshal(AssemblyInfo assemblyInfo, MavenProject mavenProject, OutputStream outputStream) throws IOException { String src = mavenProject.getBasedir() + "/target/build-sources"; StringBuffer sb = new StringBuffer(); sb.append("Imports System.Reflection\r\n").append("Imports System.Runtime.InteropServices\r\n") .append(createEntry("Description", assemblyInfo.getDescription())) .append(createEntry("Title", assemblyInfo.getTitle())) .append(createEntry("Company", assemblyInfo.getCompany())) .append(createEntry("Product", assemblyInfo.getProduct())) .append(createEntry("Copyright", assemblyInfo.getCopyright().replace("\"", "\\"))) .append(createEntry("Trademark", assemblyInfo.getTrademark())) .append(createEntry("Culture", assemblyInfo.getCulture())) .append(createEntry("Version", assemblyInfo.getVersion())); //.append(createEntry("Configuration", assemblyInfo.getConfiguration())); FileOutputStream man = null; try { String groupIdAsDir = mavenProject.getGroupId().replace(".", File.separator); File file = new File(src + "/META-INF/" + groupIdAsDir); file.mkdirs(); man = new FileOutputStream( src + "/META-INF/" + groupIdAsDir + File.separator + "AssemblyInfo." + plugin.getExtension()); man.write(sb.toString().getBytes()); } catch (IOException e) { throw new IOException(); } finally { if (man != null) { man.close(); } } }
From source file:org.apache.camel.maven.packaging.PackageComponentMojo.java
License:Apache License
public static void prepareComponent(Log log, MavenProject project, MavenProjectHelper projectHelper, File componentOutDir) throws MojoExecutionException { File camelMetaDir = new File(componentOutDir, "META-INF/services/org/apache/camel/"); StringBuilder buffer = new StringBuilder(); int count = 0; for (Resource r : project.getBuild().getResources()) { File f = new File(r.getDirectory()); if (!f.exists()) { f = new File(project.getBasedir(), r.getDirectory()); }//from w w w.j a v a2 s. c o m f = new File(f, "META-INF/services/org/apache/camel/component"); if (f.exists() && f.isDirectory()) { File[] files = f.listFiles(); if (files != null) { for (File file : files) { // skip directories as there may be a sub .resolver directory if (file.isDirectory()) { continue; } String name = file.getName(); if (name.charAt(0) != '.') { count++; if (buffer.length() > 0) { buffer.append(" "); } buffer.append(name); } } } } } if (count > 0) { Properties properties = new Properties(); String names = buffer.toString(); properties.put("components", names); properties.put("groupId", project.getGroupId()); properties.put("artifactId", project.getArtifactId()); properties.put("version", project.getVersion()); properties.put("projectName", project.getName()); if (project.getDescription() != null) { properties.put("projectDescription", project.getDescription()); } camelMetaDir.mkdirs(); File outFile = new File(camelMetaDir, "component.properties"); try { properties.store(new FileWriter(outFile), "Generated by camel-package-maven-plugin"); log.info("Generated " + outFile + " containing " + count + " Camel " + (count > 1 ? "components: " : "component: ") + names); if (projectHelper != null) { List<String> includes = new ArrayList<String>(); includes.add("**/component.properties"); projectHelper.addResource(project, componentOutDir.getPath(), includes, new ArrayList<String>()); projectHelper.attachArtifact(project, "properties", "camelComponent", outFile); } } catch (IOException e) { throw new MojoExecutionException("Failed to write properties to " + outFile + ". Reason: " + e, e); } } else { log.debug( "No META-INF/services/org/apache/camel/component directory found. Are you sure you have created a Camel component?"); } }
From source file:org.apache.camel.maven.packaging.PackageDataFormatMojo.java
License:Apache License
public static void prepareDataFormat(Log log, MavenProject project, MavenProjectHelper projectHelper, File dataFormatOutDir, File schemaOutDir) throws MojoExecutionException { File camelMetaDir = new File(dataFormatOutDir, "META-INF/services/org/apache/camel/"); Map<String, String> javaTypes = new HashMap<String, String>(); StringBuilder buffer = new StringBuilder(); int count = 0; for (Resource r : project.getBuild().getResources()) { File f = new File(r.getDirectory()); if (!f.exists()) { f = new File(project.getBasedir(), r.getDirectory()); }// w ww .jav a 2 s . c o m f = new File(f, "META-INF/services/org/apache/camel/dataformat"); if (f.exists() && f.isDirectory()) { File[] files = f.listFiles(); if (files != null) { for (File file : files) { // skip directories as there may be a sub .resolver directory if (file.isDirectory()) { continue; } String name = file.getName(); if (name.charAt(0) != '.') { count++; if (buffer.length() > 0) { buffer.append(" "); } buffer.append(name); } // find out the javaType for each data format try { String text = loadText(new FileInputStream(file)); Map<String, String> map = parseAsMap(text); String javaType = map.get("class"); if (javaType != null) { javaTypes.put(name, javaType); } } catch (IOException e) { throw new MojoExecutionException("Failed to read file " + file + ". Reason: " + e, e); } } } } } // find camel-core and grab the data format model from there, and enrich this model with information from this artifact // and create json schema model file for this data format try { if (count > 0) { Artifact camelCore = findCamelCoreArtifact(project); if (camelCore != null) { File core = camelCore.getFile(); if (core != null) { URL url = new URL("file", null, core.getAbsolutePath()); URLClassLoader loader = new URLClassLoader(new URL[] { url }); for (Map.Entry<String, String> entry : javaTypes.entrySet()) { String name = entry.getKey(); String javaType = entry.getValue(); String modelName = asModelName(name); InputStream is = loader.getResourceAsStream( "org/apache/camel/model/dataformat/" + modelName + ".json"); if (is == null) { // use file input stream if we build camel-core itself, and thus do not have a JAR which can be loaded by URLClassLoader is = new FileInputStream( new File(core, "org/apache/camel/model/dataformat/" + modelName + ".json")); } String json = loadText(is); if (json != null) { DataFormatModel dataFormatModel = new DataFormatModel(); dataFormatModel.setName(name); dataFormatModel.setTitle(""); dataFormatModel.setModelName(modelName); dataFormatModel.setLabel(""); dataFormatModel.setDescription(project.getDescription()); dataFormatModel.setJavaType(javaType); dataFormatModel.setGroupId(project.getGroupId()); dataFormatModel.setArtifactId(project.getArtifactId()); dataFormatModel.setVersion(project.getVersion()); List<Map<String, String>> rows = JSonSchemaHelper.parseJsonSchema("model", json, false); for (Map<String, String> row : rows) { if (row.containsKey("title")) { String title = row.get("title"); dataFormatModel.setTitle(asModelTitle(name, title)); } if (row.containsKey("label")) { dataFormatModel.setLabel(row.get("label")); } if (row.containsKey("javaType")) { dataFormatModel.setModelJavaType(row.get("javaType")); } // override description for camel-core, as otherwise its too generic if ("camel-core".equals(project.getArtifactId())) { if (row.containsKey("description")) { dataFormatModel.setLabel(row.get("description")); } } } log.debug("Model " + dataFormatModel); // build json schema for the data format String properties = after(json, " \"properties\": {"); String schema = createParameterJsonSchema(dataFormatModel, properties); log.debug("JSon schema\n" + schema); // write this to the directory File dir = new File(schemaOutDir, schemaSubDirectory(dataFormatModel.getJavaType())); dir.mkdirs(); File out = new File(dir, name + ".json"); FileOutputStream fos = new FileOutputStream(out, false); fos.write(schema.getBytes()); fos.close(); log.debug("Generated " + out + " containing JSon schema for " + name + " data format"); } } } } } } catch (Exception e) { throw new MojoExecutionException("Error loading dataformat model from camel-core. Reason: " + e, e); } if (count > 0) { Properties properties = new Properties(); String names = buffer.toString(); properties.put("dataFormats", names); properties.put("groupId", project.getGroupId()); properties.put("artifactId", project.getArtifactId()); properties.put("version", project.getVersion()); properties.put("projectName", project.getName()); if (project.getDescription() != null) { properties.put("projectDescription", project.getDescription()); } camelMetaDir.mkdirs(); File outFile = new File(camelMetaDir, "dataformat.properties"); try { properties.store(new FileWriter(outFile), "Generated by camel-package-maven-plugin"); log.info("Generated " + outFile + " containing " + count + " Camel " + (count > 1 ? "dataformats: " : "dataformat: ") + names); if (projectHelper != null) { List<String> includes = new ArrayList<String>(); includes.add("**/dataformat.properties"); projectHelper.addResource(project, dataFormatOutDir.getPath(), includes, new ArrayList<String>()); projectHelper.attachArtifact(project, "properties", "camelDataFormat", outFile); } } catch (IOException e) { throw new MojoExecutionException("Failed to write properties to " + outFile + ". Reason: " + e, e); } } else { log.debug( "No META-INF/services/org/apache/camel/dataformat directory found. Are you sure you have created a Camel data format?"); } }
From source file:org.apache.camel.maven.packaging.PackageLanguageMojo.java
License:Apache License
public static void prepareLanguage(Log log, MavenProject project, MavenProjectHelper projectHelper, File languageOutDir, File schemaOutDir) throws MojoExecutionException { File camelMetaDir = new File(languageOutDir, "META-INF/services/org/apache/camel/"); Map<String, String> javaTypes = new HashMap<String, String>(); StringBuilder buffer = new StringBuilder(); int count = 0; for (Resource r : project.getBuild().getResources()) { File f = new File(r.getDirectory()); if (!f.exists()) { f = new File(project.getBasedir(), r.getDirectory()); }/*w w w .java2 s . c om*/ f = new File(f, "META-INF/services/org/apache/camel/language"); if (f.exists() && f.isDirectory()) { File[] files = f.listFiles(); if (files != null) { for (File file : files) { // skip directories as there may be a sub .resolver directory such as in camel-script if (file.isDirectory()) { continue; } String name = file.getName(); if (name.charAt(0) != '.') { count++; if (buffer.length() > 0) { buffer.append(" "); } buffer.append(name); } // find out the javaType for each data format try { String text = loadText(new FileInputStream(file)); Map<String, String> map = parseAsMap(text); String javaType = map.get("class"); if (javaType != null) { javaTypes.put(name, javaType); } } catch (IOException e) { throw new MojoExecutionException("Failed to read file " + file + ". Reason: " + e, e); } } } } } // find camel-core and grab the data format model from there, and enrich this model with information from this artifact // and create json schema model file for this data format try { if (count > 0) { Artifact camelCore = findCamelCoreArtifact(project); if (camelCore != null) { File core = camelCore.getFile(); if (core != null) { URL url = new URL("file", null, core.getAbsolutePath()); URLClassLoader loader = new URLClassLoader(new URL[] { url }); for (Map.Entry<String, String> entry : javaTypes.entrySet()) { String name = entry.getKey(); String javaType = entry.getValue(); String modelName = asModelName(name); InputStream is = loader .getResourceAsStream("org/apache/camel/model/language/" + modelName + ".json"); if (is == null) { // use file input stream if we build camel-core itself, and thus do not have a JAR which can be loaded by URLClassLoader is = new FileInputStream( new File(core, "org/apache/camel/model/language/" + modelName + ".json")); } String json = loadText(is); if (json != null) { LanguageModel languageModel = new LanguageModel(); languageModel.setName(name); languageModel.setTitle(""); languageModel.setModelName(modelName); languageModel.setLabel(""); languageModel.setDescription(""); languageModel.setJavaType(javaType); languageModel.setGroupId(project.getGroupId()); languageModel.setArtifactId(project.getArtifactId()); languageModel.setVersion(project.getVersion()); List<Map<String, String>> rows = JSonSchemaHelper.parseJsonSchema("model", json, false); for (Map<String, String> row : rows) { if (row.containsKey("title")) { languageModel.setTitle(row.get("title")); } if (row.containsKey("description")) { languageModel.setDescription(row.get("description")); } if (row.containsKey("label")) { languageModel.setLabel(row.get("label")); } if (row.containsKey("javaType")) { languageModel.setModelJavaType(row.get("javaType")); } } log.debug("Model " + languageModel); // build json schema for the data format String properties = after(json, " \"properties\": {"); String schema = createParameterJsonSchema(languageModel, properties); log.debug("JSon schema\n" + schema); // write this to the directory File dir = new File(schemaOutDir, schemaSubDirectory(languageModel.getJavaType())); dir.mkdirs(); File out = new File(dir, name + ".json"); FileOutputStream fos = new FileOutputStream(out, false); fos.write(schema.getBytes()); fos.close(); log.debug("Generated " + out + " containing JSon schema for " + name + " language"); } } } } } } catch (Exception e) { throw new MojoExecutionException("Error loading language model from camel-core. Reason: " + e, e); } if (count > 0) { Properties properties = new Properties(); String names = buffer.toString(); properties.put("languages", names); properties.put("groupId", project.getGroupId()); properties.put("artifactId", project.getArtifactId()); properties.put("version", project.getVersion()); properties.put("projectName", project.getName()); if (project.getDescription() != null) { properties.put("projectDescription", project.getDescription()); } camelMetaDir.mkdirs(); File outFile = new File(camelMetaDir, "language.properties"); try { properties.store(new FileWriter(outFile), "Generated by camel-package-maven-plugin"); log.info("Generated " + outFile + " containing " + count + " Camel " + (count > 1 ? "languages: " : "language: ") + names); if (projectHelper != null) { List<String> includes = new ArrayList<String>(); includes.add("**/language.properties"); projectHelper.addResource(project, languageOutDir.getPath(), includes, new ArrayList<String>()); projectHelper.attachArtifact(project, "properties", "camelLanguage", outFile); } } catch (IOException e) { throw new MojoExecutionException("Failed to write properties to " + outFile + ". Reason: " + e, e); } } else { log.debug( "No META-INF/services/org/apache/camel/language directory found. Are you sure you have created a Camel language?"); } }
From source file:org.apache.felix.bundleplugin.BundlePlugin.java
License:Apache License
protected Builder buildOSGiBundle(MavenProject currentProject, Map originalInstructions, Properties properties, Jar[] classpath) throws Exception { properties.putAll(getDefaultProperties(currentProject)); properties.putAll(transformDirectives(originalInstructions)); Builder builder = new Builder(); builder.setBase(currentProject.getBasedir()); builder.setProperties(properties);//w w w.j a v a2s . c o m builder.setClasspath(classpath); // update BND instructions to add included Maven resources includeMavenResources(currentProject, builder, getLog()); // calculate default export/private settings based on sources if (builder.getProperty(Analyzer.PRIVATE_PACKAGE) == null || builder.getProperty(Analyzer.EXPORT_PACKAGE) == null) { addLocalPackages(currentProject.getCompileSourceRoots(), builder); } // update BND instructions to embed selected Maven dependencies Collection embeddableArtifacts = getEmbeddableArtifacts(currentProject, builder); new DependencyEmbedder(getLog(), embeddableArtifacts).processHeaders(builder); dumpInstructions("BND Instructions:", builder.getProperties(), getLog()); dumpClasspath("BND Classpath:", builder.getClasspath(), getLog()); builder.build(); Jar jar = builder.getJar(); dumpManifest("BND Manifest:", jar.getManifest(), getLog()); String[] removeHeaders = builder.getProperty(Analyzer.REMOVE_HEADERS, "").split(","); mergeMavenManifest(currentProject, jar, removeHeaders, getLog()); builder.setJar(jar); dumpManifest("Final Manifest:", jar.getManifest(), getLog()); return builder; }