public void initialize() { modelReader = new MavenXpp3Reader(); }
Model model = null; FileReader reader = null; MavenXpp3Reader mavenreader = new MavenXpp3Reader(); try { reader = new FileReader(pomfile); model = mavenreader.read(reader); model.setPomFile(pomfile); }catch(Exception ex){} MavenProject project = new MavenProject(model);
try { reader = new FileReader(pomFile); MavenXpp3Reader xpp3Reader = new MavenXpp3Reader(); Model model = xpp3Reader.read(reader); projVersionStr = model.getVersion();
private static String getPomVersion() { try { MavenXpp3Reader pomReader = new MavenXpp3Reader(); Model model = pomReader .read(new InputStreamReader(new FileInputStream("../pom.xml"), StandardCharsets.UTF_8)); return model.getVersion(); } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } }
/** * Constructs a new helper objects and initializes itself. */ public BundleTestInfo() { try (final FileReader reader = new FileReader("pom.xml")) { // get a raw POM view, not a fully realized POM object. final Model model = new MavenXpp3Reader().read(reader); this.project = new MavenProject(model); } catch (final IOException | XmlPullParserException e) { throw new IllegalStateException("Could not read pom.xml", e); } }
MavenXpp3Reader modelReader = new MavenXpp3Reader(); try
MavenXpp3Reader modelReader = new MavenXpp3Reader(); try
private Model read( Reader reader, boolean strict, InputSource source ) throws IOException { try { if ( source != null ) { return new MavenXpp3ReaderEx().read( reader, strict, source ); } else { return new MavenXpp3Reader().read( reader, strict ); } } catch ( XmlPullParserException e ) { throw new ModelParseException( e.getMessage(), e.getLineNumber(), e.getColumnNumber(), e ); } }
MavenXpp3Reader reader = new MavenXpp3Reader(); Model model = reader.read(new FileReader(mypom));
/** * Reads the Maven pom file to get build the {@link Model}. * * @param pomFile to be read * @return {@link Model} represeting the Maven project */ private Model readMavenPomFile(File pomFile) { MavenXpp3Reader mavenReader = new MavenXpp3Reader(); try (FileReader reader = new FileReader(pomFile)) { return mavenReader.read(reader); } catch (Exception e) { throw new RuntimeException("Error while reading Maven model from " + pomFile, e); } }
public LocalMavenPluginBundle(byte[] jarBytes) { this.jarBytes = jarBytes; try { JarInputStream jarInputStream = new JarInputStream(new ByteArrayInputStream(jarBytes)); JarEntry nextJarEntry = jarInputStream.getNextJarEntry(); while (nextJarEntry != null) { String name = nextJarEntry.getName(); if (name.startsWith("META-INF/maven") && name.endsWith("/pom.xml")) { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); IOUtils.copy(jarInputStream, byteArrayOutputStream); pomBytes = byteArrayOutputStream.toByteArray(); MavenXpp3Reader mavenreader = new MavenXpp3Reader(); try { model = mavenreader.read(new ByteArrayInputStream(pomBytes)); } catch (XmlPullParserException e) { e.printStackTrace(); } } nextJarEntry = jarInputStream.getNextJarEntry(); } } catch (IOException e) { e.printStackTrace(); } }
/** * Creates a {@link Model} by reading the {@code pom.xml} file. * * @param pomFile to parse and read the model * @return {@link Model} representing the Maven project from pom file. */ public static Model createMavenProject(File pomFile) { MavenXpp3Reader mavenReader = new MavenXpp3Reader(); if (pomFile != null && pomFile.exists()) { try (FileReader reader = new FileReader(pomFile)) { Model model = mavenReader.read(reader); model.setPomFile(pomFile); return model; } catch (Exception e) { throw new RuntimeException("Couldn't get Maven Artifact from pom: " + pomFile); } } throw new IllegalArgumentException("pom file doesn't exits for path: " + pomFile); } }
/** * Returns the {@link Model} from a given artifact folder * * @param artifactFolder folder containing the exploded artifact file. * @return the {@link Model} from the {@value DeployableArtifactDescriptor#MULE_POM} file if available * @throws ArtifactDescriptorCreateException if the folder does not contain a {@value DeployableArtifactDescriptor#MULE_POM} * file or the file can' be loaded */ public static Model getPomModelFolder(File artifactFolder) { final File artifactPom = lookupPomFromMavenLocation(artifactFolder); MavenXpp3Reader reader = new MavenXpp3Reader(); Model model; try (FileReader artifactPomFileReader = new FileReader(artifactPom)) { model = reader.read(artifactPomFileReader); } catch (IOException | XmlPullParserException e) { throw new ArtifactDescriptorCreateException(format("There was an issue reading '%s' for the artifact '%s'", artifactPom.getName(), artifactFolder.getAbsolutePath()), e); } return model; }
/** * Extract the information from the pom * @param path the path to the pom * @param parent the parent pom * @throws IOException when the file does not exist * @throws XmlPullParserException when the file is corrupted */ public SpoonPom(String path, SpoonPom parent, MavenLauncher.SOURCE_TYPE sourceType, Environment environment) throws IOException, XmlPullParserException { this.parent = parent; this.sourceType = sourceType; this.environment = environment; if (!path.endsWith(".xml") && !path.endsWith(".pom")) { path = Paths.get(path, "pom.xml").toString(); } this.pomFile = new File(path); if (!pomFile.exists()) { throw new IOException("Pom does not exists."); } this.directory = pomFile.getParentFile(); MavenXpp3Reader pomReader = new MavenXpp3Reader(); try (FileReader reader = new FileReader(pomFile)) { this.model = pomReader.read(reader); for (String module : model.getModules()) { addModule(new SpoonPom(Paths.get(pomFile.getParent(), module).toString(), this, sourceType, environment)); } } catch (FileNotFoundException e) { throw new IOException("Pom does not exists."); } }
/** * Returns the {@link Model} from a given artifact folder * * @param artifactFile file containing the artifact content. * @return the {@link Model} from the {@value ArtifactPluginDescriptor#MULE_PLUGIN_POM} file if available * @throws ArtifactDescriptorCreateException if the artifact jar does not contain a * {@value ArtifactPluginDescriptor#MULE_PLUGIN_POM} file or the file can' be loaded */ public static Model getPomModelFromJar(File artifactFile) { String pomFilePath = MULE_ARTIFACT_PATH_INSIDE_JAR + "/" + MULE_PLUGIN_POM; try { MavenXpp3Reader reader = new MavenXpp3Reader(); return reader.read(new ByteArrayInputStream(loadFileContentFrom(getPomUrlFromJar(artifactFile)).get())); } catch (IOException | XmlPullParserException e) { throw new ArtifactDescriptorCreateException(format("There was an issue reading '%s' for the artifact '%s'", pomFilePath, artifactFile.getAbsolutePath()), e); } }
/** * Loads the model for this stub from the specified POM. For convenience, any checked exception caused by I/O or * parser errors will be wrapped into an unchecked exception. * * @param pomFile The path to the POM file to load, must not be <code>null</code>. If this path is relative, it * is resolved against the return value of {@link #getBasedir()}. */ protected void readModel( File pomFile ) { if ( !pomFile.isAbsolute() ) { pomFile = new File( getBasedir(), pomFile.getPath() ); } try { setModel( new MavenXpp3Reader().read( ReaderFactory.newXmlReader( pomFile ) ) ); } catch ( IOException e ) { throw new RuntimeException( "Failed to read POM file: " + pomFile, e ); } catch ( XmlPullParserException e ) { throw new RuntimeException( "Failed to parse POM file: " + pomFile, e ); } }
public SPluginBundleVersion extractPluginBundleVersionFromJar(Path jarFilePath, boolean isLocal) throws PluginException { String filename = jarFilePath.getFileName().toString(); PluginBundleVersionIdentifier pluginBundleVersionIdentifier = PluginBundleVersionIdentifier.fromFileName(filename); PluginBundleIdentifier pluginBundleIdentifier = pluginBundleVersionIdentifier.getPluginBundleIdentifier(); try (JarFile jarFile = new JarFile(jarFilePath.toFile())) { ZipEntry pomEntry = jarFile.getEntry("META-INF/maven/" + pluginBundleIdentifier.getGroupId() + "/" + pluginBundleIdentifier.getArtifactId() + "/" + "pom.xml"); if (pomEntry == null) { throw new PluginException("No pom.xml found in JAR file " + jarFilePath.toString()); } MavenXpp3Reader mavenreader = new MavenXpp3Reader(); Model model = mavenreader.read(jarFile.getInputStream(pomEntry)); SPluginBundleVersion sPluginBundleVersion = createPluginBundleVersionFromMavenModel(model, isLocal); return sPluginBundleVersion; } catch (IOException e) { throw new PluginException(e); } catch (XmlPullParserException e) { throw new PluginException(e); } }
private static Pair<File, File> getJobJarFiles() { String version; try { MavenXpp3Reader pomReader = new MavenXpp3Reader(); Model model = pomReader.read(new FileReader("../pom.xml")); version = model.getVersion(); } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } File jobJar = new File("../job/target", "kylin-job-" + version + "-job.jar"); File coprocessorJar = new File("../storage/target", "kylin-storage-" + version + "-coprocessor.jar"); return new Pair<File, File>(jobJar, coprocessorJar); }
public SPluginBundle extractPluginBundleFromJar(Path jarFilePath) throws PluginException { String filename = jarFilePath.getFileName().toString(); PluginBundleVersionIdentifier pluginBundleVersionIdentifier = PluginBundleVersionIdentifier.fromFileName(filename); try (JarFile jarFile = new JarFile(jarFilePath.toFile())) { String pomLocation = "META-INF/maven/" + pluginBundleVersionIdentifier.getPluginBundleIdentifier().getGroupId() + "/" + pluginBundleVersionIdentifier.getPluginBundleIdentifier().getArtifactId() + "/" + "pom.xml"; ZipEntry pomEntry = jarFile.getEntry(pomLocation); if (pomEntry == null) { throw new PluginException("No pom.xml found in JAR file " + jarFilePath.toString() + ", " + pomLocation); } MavenXpp3Reader mavenreader = new MavenXpp3Reader(); Model model = mavenreader.read(jarFile.getInputStream(pomEntry)); SPluginBundle sPluginBundle = new SPluginBundle(); sPluginBundle.setOrganization(model.getOrganization().getName()); sPluginBundle.setName(model.getName()); return sPluginBundle; } catch (IOException e) { throw new PluginException(e); } catch (XmlPullParserException e) { throw new PluginException(e); } }
MavenXpp3Reader mavenreader = new MavenXpp3Reader();