org.codehaus.plexus.util.ReaderFactory Java Examples

The following examples show how to use org.codehaus.plexus.util.ReaderFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MojoUtilsTest.java    From vertx-maven-plugin with Apache License 2.0 5 votes vote down vote up
private Model buildModel(File pomFile) {
    try {
        return new MavenXpp3Reader().read(ReaderFactory.newXmlReader(pomFile));
    } catch (IOException var3) {
        throw new RuntimeException("Failed to read POM file: " + pomFile, var3);
    } catch (XmlPullParserException var4) {
        throw new RuntimeException("Failed to parse POM file: " + pomFile, var4);
    }
}
 
Example #2
Source File: ExtraManifestInfoTest.java    From vertx-maven-plugin with Apache License 2.0 5 votes vote down vote up
private Model buildModel(File pomFile) {
    try {
        return new MavenXpp3Reader().read(ReaderFactory.newXmlReader(pomFile));
    } catch (IOException var3) {
        throw new RuntimeException("Failed to read POM file: " + pomFile, var3);
    } catch (XmlPullParserException var4) {
        throw new RuntimeException("Failed to parse POM file: " + pomFile, var4);
    }
}
 
Example #3
Source File: MojoUtilsTest.java    From vertx-maven-plugin with Apache License 2.0 5 votes vote down vote up
private Model buildModel(File pomFile) {
    try {
        return new MavenXpp3Reader().read(ReaderFactory.newXmlReader(pomFile));
    } catch (IOException var3) {
        throw new RuntimeException("Failed to read POM file: " + pomFile, var3);
    } catch (XmlPullParserException var4) {
        throw new RuntimeException("Failed to parse POM file: " + pomFile, var4);
    }
}
 
Example #4
Source File: ExtraManifestInfoTest.java    From vertx-maven-plugin with Apache License 2.0 5 votes vote down vote up
private Model buildModel(File pomFile) {
    try {
        return new MavenXpp3Reader().read(ReaderFactory.newXmlReader(pomFile));
    } catch (IOException var3) {
        throw new RuntimeException("Failed to read POM file: " + pomFile, var3);
    } catch (XmlPullParserException var4) {
        throw new RuntimeException("Failed to parse POM file: " + pomFile, var4);
    }
}
 
Example #5
Source File: FormatterMojo.java    From formatter-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Read the given file and return the content as a string.
 *
 * @param file
 *            the file
 * 
 * @return the string
 * 
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
private String readFileAsString(File file) throws IOException {
    StringBuilder fileData = new StringBuilder(1000);
    try (BufferedReader reader = new BufferedReader(ReaderFactory.newReader(file, this.encoding))) {
        char[] buf = new char[1024];
        int numRead = 0;
        while ((numRead = reader.read(buf)) != -1) {
            String readData = String.valueOf(buf, 0, numRead);
            fileData.append(readData);
            buf = new char[1024];
        }
    }
    return fileData.toString();
}
 
Example #6
Source File: TypeScriptDTOGeneratorMojoProjectStub.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
/** Default constructor */
public TypeScriptDTOGeneratorMojoProjectStub() {
  MavenXpp3Reader pomReader = new MavenXpp3Reader();
  Model model;
  try {
    model = pomReader.read(ReaderFactory.newXmlReader(new File(getBasedir(), "pom.xml")));
    setModel(model);
  } catch (Exception e) {
    throw new RuntimeException(e);
  }

  setGroupId(model.getGroupId());
  setArtifactId(model.getArtifactId());
  setVersion(model.getVersion());
  setName(model.getName());
  setUrl(model.getUrl());
  setPackaging(model.getPackaging());

  Build build = new Build();
  build.setFinalName(model.getArtifactId());
  build.setDirectory(getBasedir() + "/target");
  build.setSourceDirectory(getBasedir() + "/src/main/java");
  build.setOutputDirectory(getBasedir() + "/target/classes");
  build.setTestSourceDirectory(getBasedir() + "/src/test/java");
  build.setTestOutputDirectory(getBasedir() + "/target/test-classes");
  setBuild(build);

  List compileSourceRoots = new ArrayList();
  compileSourceRoots.add(getBasedir() + "/src/main/java");
  setCompileSourceRoots(compileSourceRoots);

  List testCompileSourceRoots = new ArrayList();
  testCompileSourceRoots.add(getBasedir() + "/src/test/java");
  setTestCompileSourceRoots(testCompileSourceRoots);
}
 
Example #7
Source File: PomHelper.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Reads a file into a String.
 *
 * @param outFile The file to read.
 * @return String The content of the file.
 * @throws java.io.IOException when things go wrong.
 */
public static StringBuilder readXmlFile( File outFile )
    throws IOException
{
    try( Reader reader = ReaderFactory.newXmlReader( outFile ) )
    {
        return new StringBuilder( IOUtil.toString( reader ) );
    }
}
 
Example #8
Source File: ProjectStub.java    From docker-maven-plugin with Apache License 2.0 5 votes vote down vote up
public ProjectStub(File pom) {
  final MavenXpp3Reader pomReader = new MavenXpp3Reader();
  Model model;
  try {
    model = pomReader.read(ReaderFactory.newXmlReader(pom));
    setModel(model);
  } catch (Exception e) {
    throw new RuntimeException(e);
  }

  setGroupId(model.getGroupId());
  setArtifactId(model.getArtifactId());
  setVersion(model.getVersion());
  setName(model.getName());
  setUrl(model.getUrl());
  setPackaging(model.getPackaging());
  setBuild(model.getBuild());

  final List<String> compileSourceRoots = new ArrayList<>();
  compileSourceRoots.add(getBasedir() + "/src/main/java");
  setCompileSourceRoots(compileSourceRoots);

  final List<String> testCompileSourceRoots = new ArrayList<>();
  testCompileSourceRoots.add(getBasedir() + "/src/test/java");
  setTestCompileSourceRoots(testCompileSourceRoots);

  // normalize some expressions
  getBuild().setDirectory("${project.basedir}/target");
  getBuild().setTestOutputDirectory(new File(getBasedir(), "target/classes").getAbsolutePath());
}
 
Example #9
Source File: LegacyPluginDescriptors.java    From takari-lifecycle with Eclipse Public License 1.0 5 votes vote down vote up
public static Collection<MojoDescriptor> readMojos(InputStream is) throws IOException, XmlPullParserException {
  Reader reader = ReaderFactory.newXmlReader(is);
  org.apache.maven.plugin.descriptor.PluginDescriptor pluginDescriptor;
  try {
    pluginDescriptor = new PluginDescriptorBuilder().build(reader);
  } catch (PlexusConfigurationException e) {
    Throwables.propagateIfPossible(e.getCause(), IOException.class, XmlPullParserException.class);
    throw Throwables.propagate(e);
  }
  List<MojoDescriptor> result = new ArrayList<>();
  for (org.apache.maven.plugin.descriptor.MojoDescriptor mojo : pluginDescriptor.getMojos()) {
    result.add(toMojoDescriptor(mojo));
  }
  return result;
}
 
Example #10
Source File: FormatterMojo.java    From formatter-maven-plugin with Apache License 2.0 4 votes vote down vote up
/**
 * Execute.
 *
 * @throws MojoExecutionException
 *             the mojo execution exception
 * @throws MojoFailureException
 *             the mojo failure exception
 * 
 * @see org.apache.maven.plugin.AbstractMojo#execute()
 */
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if (this.skipFormatting) {
        getLog().info("Formatting is skipped");
        return;
    }

    long startClock = System.currentTimeMillis();

    if (StringUtils.isEmpty(this.encoding)) {
        this.encoding = ReaderFactory.FILE_ENCODING;
        getLog().warn("File encoding has not been set, using platform encoding (" + this.encoding
                + ") to format source files, i.e. build is platform dependent!");
    } else {
        if (!Charset.isSupported(this.encoding)) {
            throw new MojoExecutionException("Encoding '" + this.encoding + "' is not supported");
        }
        getLog().info("Using '" + this.encoding + "' encoding to format source files.");
    }

    List<File> files = new ArrayList<>();
    if (this.directories != null) {
        for (File directory : this.directories) {
            if (directory.exists() && directory.isDirectory()) {
                files.addAll(addCollectionFiles(directory));
            }
        }
    } else {
        // Using defaults of source main and test dirs
        if (this.sourceDirectory != null && this.sourceDirectory.exists() && this.sourceDirectory.isDirectory()) {
            files.addAll(addCollectionFiles(this.sourceDirectory));
        }
        if (this.testSourceDirectory != null && this.testSourceDirectory.exists()
                && this.testSourceDirectory.isDirectory()) {
            files.addAll(addCollectionFiles(this.testSourceDirectory));
        }
    }

    int numberOfFiles = files.size();
    Log log = getLog();
    log.info("Number of files to be formatted: " + numberOfFiles);

    if (numberOfFiles > 0) {
        createCodeFormatter();
        ResultCollector rc = new ResultCollector();
        Properties hashCache = readFileHashCacheFile();

        String basedirPath = getBasedirPath();
        for (int i = 0, n = files.size(); i < n; i++) {
            File file = files.get(i);
            if (file.exists()) {
                if (file.canWrite()) {
                    formatFile(file, rc, hashCache, basedirPath);
                } else {
                    rc.readOnlyCount++;
                }
            } else {
                rc.failCount++;
            }
        }

        storeFileHashCache(hashCache);

        long endClock = System.currentTimeMillis();

        log.info("Successfully formatted:          " + rc.successCount + FILE_S);
        log.info("Fail to format:                  " + rc.failCount + FILE_S);
        log.info("Skipped:                         " + rc.skippedCount + FILE_S);
        log.info("Read only skipped:               " + rc.readOnlyCount + FILE_S);
        log.info("Approximate time taken:          " + ((endClock - startClock) / 1000) + "s");
    }
}
 
Example #11
Source File: ProjectStub.java    From dependency-mediator with Apache License 2.0 4 votes vote down vote up
/**
 * Default constructor
 */
public ProjectStub() {
    MavenXpp3Reader pomReader = new MavenXpp3Reader();
    Model model;
    try {
        model = pomReader.read(ReaderFactory.newXmlReader(new File(getBasedir(), "pom.xml")));
        setModel(model);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    Artifact artifact = new ArtifactStub();
    artifact.setArtifactId(model.getArtifactId());
    artifact.setGroupId(model.getGroupId());
    artifact.setVersion(model.getVersion());
    setArtifact(artifact);

    setGroupId(model.getGroupId());
    setArtifactId(model.getArtifactId());
    setVersion(model.getVersion());
    setName(model.getName());
    setUrl(model.getUrl());
    setPackaging(model.getPackaging());

    Build build = new Build();
    build.setFinalName(model.getArtifactId());
    build.setDirectory(getBasedir() + "/target");
    build.setSourceDirectory(getBasedir() + "/src/main/java");
    build.setOutputDirectory(getBasedir() + "/target/classes");
    build.setTestSourceDirectory(getBasedir() + "/src/test/java");
    build.setTestOutputDirectory(getBasedir() + "/target/test-classes");
    setBuild(build);

    List<String> compileSourceRoots = new ArrayList<String>();
    compileSourceRoots.add(getBasedir() + "/src/main/java");
    setCompileSourceRoots(compileSourceRoots);

    List<String> testCompileSourceRoots = new ArrayList<String>();
    testCompileSourceRoots.add(getBasedir() + "/src/test/java");
    setTestCompileSourceRoots(testCompileSourceRoots);
}
 
Example #12
Source File: CustomModelProcessor.java    From tutorials with MIT License 4 votes vote down vote up
@Override
public Model read(InputStream input, Map<String, ?> options) throws IOException, ModelParseException {
    try (final Reader in = ReaderFactory.newPlatformReader(input)) {
        return read(in, options);
    }
}
 
Example #13
Source File: NetbeansBuildActionXpp3Reader.java    From netbeans with Apache License 2.0 3 votes vote down vote up
/**
 * Method read.
 * 
 * @param in
 * @param strict
 * @throws IOException
 * @throws XmlPullParserException
 * @return ActionToGoalMapping
 */
public ActionToGoalMapping read(InputStream in, boolean strict)
    throws IOException, XmlPullParserException
{
    Reader reader = ReaderFactory.newXmlReader( in );
    
    return read( reader, strict );
}
 
Example #14
Source File: NetbeansBuildActionXpp3Reader.java    From netbeans with Apache License 2.0 3 votes vote down vote up
/**
 * Method read.
 * 
 * @param in
 * @throws IOException
 * @throws XmlPullParserException
 * @return ActionToGoalMapping
 */
public ActionToGoalMapping read(InputStream in)
    throws IOException, XmlPullParserException
{
    Reader reader = ReaderFactory.newXmlReader( in );
    
    return read( reader );
}