org.codehaus.plexus.logging.console.ConsoleLogger Java Examples

The following examples show how to use org.codehaus.plexus.logging.console.ConsoleLogger. 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: DynamoDBLocal.java    From geowave with Apache License 2.0 6 votes vote down vote up
protected boolean install() throws IOException {
  HttpURLConnection.setFollowRedirects(true);
  final URL url = new URL(DYNDB_URL + DYNDB_TAR);

  final File downloadFile = new File(dynLocalDir, DYNDB_TAR);
  if (!downloadFile.exists()) {
    try (FileOutputStream fos = new FileOutputStream(downloadFile)) {
      IOUtils.copyLarge(url.openStream(), fos);
      fos.flush();
    }
  }

  final TarGZipUnArchiver unarchiver = new TarGZipUnArchiver();
  unarchiver.enableLogging(new ConsoleLogger(Logger.WARN, "DynamoDB Local Unarchive"));
  unarchiver.setSourceFile(downloadFile);
  unarchiver.setDestDirectory(dynLocalDir);
  unarchiver.extract();

  if (!downloadFile.delete()) {
    LOGGER.warn("cannot delete " + downloadFile.getAbsolutePath());
  }

  // Check the install
  if (!isInstalled()) {
    LOGGER.error("DynamoDB Local install failed");
    return false;
  }

  return true;
}
 
Example #2
Source File: TarGzArchive.java    From dropwizard-experiment with MIT License 6 votes vote down vote up
private static File tar(Set<File> files, String folder) throws IOException {
    TarArchiver tarArchive = new TarArchiver();
    tarArchive.enableLogging(new ConsoleLogger(Logger.LEVEL_DISABLED, "console"));
    for (File file : files) {
        // The starting ./ in the folder name is required for Heroku to be able to unpack the files correctly.
        if (file.isFile()) {
            tarArchive.addFile(file, "./" + folder + "/" + file.getName());
        } else if (file.isDirectory()) {
            tarArchive.addDirectory(file, "./" + folder + "/" + file.getName() + "/");
        }
    }

    File tarFile = File.createTempFile("TarGzArchive", ".tar");
    tarArchive.setDestFile(tarFile);
    tarArchive.createArchive();

    return tarFile;
}
 
Example #3
Source File: JavaFXRunMojoTestCase.java    From javafx-maven-plugin with Apache License 2.0 5 votes vote down vote up
private String execute(AbstractMojo mojo) throws MojoFailureException, MojoExecutionException, InterruptedException {
    PrintStream out = System.out;
    StringOutputStream stringOutputStream = new StringOutputStream();
    System.setOut(new PrintStream(stringOutputStream));
    mojo.setLog(new DefaultLog(new ConsoleLogger(Logger.LEVEL_ERROR, "javafx:run")));

    try {
        mojo.execute();
    } finally {
        Thread.sleep(300);
        System.setOut(out);
    }

    return stringOutputStream.toString();
}
 
Example #4
Source File: ArchiveUtil.java    From elasticsearch-maven-plugin with Apache License 2.0 5 votes vote down vote up
public static void extractTarGz(File archiveFile, File targetDir) {
	TarGZipUnArchiver unArchiver = new TarGZipUnArchiver(archiveFile);
	unArchiver.setDestDirectory(targetDir);
	// We don't want logging, but this is necessary to avoid an NPE
	unArchiver.enableLogging(new ConsoleLogger(ConsoleLogger.LEVEL_DISABLED, "console"));
	unArchiver.extract();
}
 
Example #5
Source File: TarGzArchive.java    From dropwizard-experiment with MIT License 5 votes vote down vote up
/**
 * Unpack a .tar.gz archive and return the folder it was unpacked in.
 *
 * @param tarGz The archive
 * @return The unpacked folder
 */
public static File unpack(File tarGz) {
    File unpackDir = Files.createTempDir();
    unpackDir.deleteOnExit();

    TarGZipUnArchiver unArchiver = new TarGZipUnArchiver(tarGz);
    // Needed to avoid a null pointer...
    unArchiver.enableLogging(new ConsoleLogger(Logger.LEVEL_DISABLED, "console"));
    unArchiver.setDestDirectory(unpackDir);
    unArchiver.extract();

    return unpackDir;
}
 
Example #6
Source File: TarGzArchiveTest.java    From dropwizard-experiment with MIT License 5 votes vote down vote up
private List<File> unpack(File tgzFile) {
    TarGZipUnArchiver unarchiver = new TarGZipUnArchiver(tgzFile);
    unarchiver.enableLogging(new ConsoleLogger(Logger.LEVEL_DISABLED, "console"));
    unarchiver.setDestDirectory(unpackDir);
    unarchiver.extract();

    return ImmutableList.copyOf(unpackDir.listFiles());
}
 
Example #7
Source File: Utils.java    From usergrid with Apache License 2.0 5 votes vote down vote up
/**
 * @param jarFile Jar file to be extracted
 * @param destinationFolder Folder which the jarFile will be extracted to. Jar file's root will be this folder once
 * it is extracted.
 */
public static void extractJar( File jarFile, String destinationFolder ) throws MojoExecutionException {
    try {
        ZipUnArchiver unArchiver = new ZipUnArchiver( jarFile );
        unArchiver.enableLogging( new ConsoleLogger( org.codehaus.plexus.logging.Logger.LEVEL_INFO, "console" ) );
        unArchiver.setDestDirectory( new File( destinationFolder ) );
        unArchiver.extract();
    }
    catch ( Exception e ) {
        throw new MojoExecutionException( "Error while extracting JAR file", e );
    }
}
 
Example #8
Source File: Utils.java    From usergrid with Apache License 2.0 5 votes vote down vote up
/**
 * @param jarFile Jar file to be created
 * @param sourceFolder Jar file will be created out of the contents of this folder. This corresponds to the root
 * folder of the jar file once it is created.
 */
public static void archiveWar( File jarFile, String sourceFolder ) throws MojoExecutionException {
    try {
        ZipArchiver archiver = new ZipArchiver();
        archiver.enableLogging( new ConsoleLogger( org.codehaus.plexus.logging.Logger.LEVEL_INFO, "console" ) );
        archiver.setDestFile( jarFile );
        archiver.addDirectory( new File( sourceFolder ), "", new String[] { "**/*" }, null );
        archiver.createArchive();
    }
    catch ( Exception e ) {
        throw new MojoExecutionException( "Error while creating WAR file", e );
    }
}
 
Example #9
Source File: AnsiLoggerTest.java    From jkube with Eclipse Public License 2.0 4 votes vote down vote up
public TestLog() {
    super(new ConsoleLogger(1, "console"));
}
 
Example #10
Source File: ExecMojoTest.java    From exec-maven-plugin with Apache License 2.0 4 votes vote down vote up
/**
 * 
 * @param pom the pom file
 * @param goal the goal to execute
 * @return output from System.out during mojo execution
 * @throws Exception if any exception occurs
 */
protected String execute( File pom, String goal )
    throws Exception
{

    ExecMojo mojo;
    mojo = (ExecMojo) lookupMojo( goal, pom );

    setUpProject( pom, mojo );

    MavenProject project = (MavenProject) getVariableValueFromObject( mojo, "project" );

    // why isn't this set up by the harness based on the default-value? TODO get to bottom of this!
    // setVariableValueToObject( mojo, "includeProjectDependencies", Boolean.TRUE );
    // setVariableValueToObject( mojo, "killAfter", new Long( -1 ) );

    assertNotNull( mojo );
    assertNotNull( project );

    // trap System.out
    PrintStream out = System.out;
    StringOutputStream stringOutputStream = new StringOutputStream();
    System.setOut( new PrintStream( stringOutputStream ) );
    // ensure we don't log unnecessary stuff which would interfere with assessing success of tests
    mojo.setLog( new DefaultLog( new ConsoleLogger( Logger.LEVEL_ERROR, "exec:exec" ) ) );

    try
    {
        mojo.execute();
    }
    catch ( Throwable e )
    {
        e.printStackTrace( System.err );
        fail( e.getMessage() );
    }
    finally
    {
        System.setOut( out );
    }

    return stringOutputStream.toString();
}
 
Example #11
Source File: ExecJavaMojoTest.java    From exec-maven-plugin with Apache License 2.0 4 votes vote down vote up
/**
 * @return output from System.out during mojo execution
 */
private String execute( File pom, String goal )
    throws Exception
{

    ExecJavaMojo mojo;
    mojo = (ExecJavaMojo) lookupMojo( goal, pom );

    setUpProject( pom, mojo );

    MavenProject project = (MavenProject) getVariableValueFromObject( mojo, "project" );

    // why isn't this set up by the harness based on the default-value? TODO get to bottom of this!
    setVariableValueToObject( mojo, "includeProjectDependencies", Boolean.TRUE );
    setVariableValueToObject( mojo, "killAfter", (long) -1 );
    setVariableValueToObject( mojo, "cleanupDaemonThreads", Boolean.TRUE );
    setVariableValueToObject( mojo, "classpathScope", "compile" );

    assertNotNull( mojo );
    assertNotNull( project );

    // trap System.out
    PrintStream out = System.out;
    StringOutputStream stringOutputStream = new StringOutputStream();
    System.setOut( new PrintStream( stringOutputStream ) );
    // ensure we don't log unnecessary stuff which would interfere with assessing success of tests
    mojo.setLog( new DefaultLog( new ConsoleLogger( Logger.LEVEL_ERROR, "exec:java" ) ) );

    try
    {
        mojo.execute();
    }
    finally
    {
        // see testUncooperativeThread() for explaination
        Thread.sleep( 300 ); // time seems about right
        System.setOut( out );
    }

    return stringOutputStream.toString();
}
 
Example #12
Source File: BaseMojoTest.java    From docker-maven-plugin with Apache License 2.0 4 votes vote down vote up
protected BaseMojoTest() {
    this.consoleLogger = new ConsoleLogger(1, "console");
    this.ansiLogger = new AnsiLogger(new DefaultLog(this.consoleLogger), false, null);
}
 
Example #13
Source File: AnsiLoggerTest.java    From docker-maven-plugin with Apache License 2.0 4 votes vote down vote up
public TestLog() {
    super(new ConsoleLogger());
}
 
Example #14
Source File: KuduLocal.java    From geowave with Apache License 2.0 4 votes vote down vote up
private boolean install() throws IOException, ArchiveException {
  LOGGER.info("Installing {}", KUDU_DEB_PACKAGE);

  LOGGER.debug("downloading kudu debian package");
  final File debPackageFile = new File(kuduLocalDir, KUDU_DEB_PACKAGE);
  if (!debPackageFile.exists()) {
    HttpURLConnection.setFollowRedirects(true);
    final URL url = new URL(KUDU_REPO_URL + KUDU_DEB_PACKAGE);
    try (FileOutputStream fos = new FileOutputStream(debPackageFile)) {
      IOUtils.copy(url.openStream(), fos);
      fos.flush();
    }
  }

  LOGGER.debug("extracting kudu debian package data contents");
  final File debDataTarGz = new File(kuduLocalDir, "data.tar.gz");
  if (!debDataTarGz.exists()) {
    try (FileInputStream fis = new FileInputStream(debPackageFile);
        ArchiveInputStream debInputStream =
            new ArchiveStreamFactory().createArchiveInputStream("ar", fis)) {
      ArchiveEntry entry = null;
      while ((entry = debInputStream.getNextEntry()) != null) {
        if (debDataTarGz.getName().equals(entry.getName())) {
          try (FileOutputStream fos = new FileOutputStream(debDataTarGz)) {
            IOUtils.copy(debInputStream, fos);
          }
          break;
        }
      }
    }
  }

  LOGGER.debug("extracting kudu data contents");
  final TarGZipUnArchiver unarchiver = new TarGZipUnArchiver();
  unarchiver.enableLogging(new ConsoleLogger(Logger.WARN, "Kudu Local Unarchive"));
  unarchiver.setSourceFile(debDataTarGz);
  unarchiver.setDestDirectory(kuduLocalDir);
  unarchiver.extract();

  for (final File f : new File[] {debPackageFile, debDataTarGz}) {
    if (!f.delete()) {
      LOGGER.warn("cannot delete {}", f.getAbsolutePath());
    }
  }

  LOGGER.debug("moving kudu master and tablet binaries to {}", kuduLocalDir);
  // move the master and tablet server binaries into the kudu local directory
  final Path kuduBin =
      Paths.get(kuduLocalDir.getAbsolutePath(), "usr", "lib", "kudu", "sbin-release");
  final File kuduMasterBinary = kuduBin.resolve(KUDU_MASTER).toFile();
  final File kuduTabletBinary = kuduBin.resolve(KUDU_TABLET).toFile();
  kuduMasterBinary.setExecutable(true);
  kuduTabletBinary.setExecutable(true);
  FileUtils.moveFileToDirectory(kuduMasterBinary, kuduLocalDir, false);
  FileUtils.moveFileToDirectory(kuduTabletBinary, kuduLocalDir, false);

  if (isInstalled()) {
    LOGGER.info("Kudu Local installation successful");
    return true;
  } else {
    LOGGER.error("Kudu Local installation failed");
    return false;
  }
}
 
Example #15
Source File: BigtableEmulator.java    From geowave with Apache License 2.0 4 votes vote down vote up
protected boolean install() throws IOException {
  final URL url = new URL(downloadUrl + "/" + fileName);

  final File downloadFile = new File(sdkDir.getParentFile(), fileName);
  if (!downloadFile.exists()) {
    try (FileOutputStream fos = new FileOutputStream(downloadFile)) {
      IOUtils.copyLarge(url.openStream(), fos);
      fos.flush();
    }
  }
  if (downloadFile.getName().endsWith(".zip")) {
    ZipUtils.unZipFile(downloadFile, sdkDir.getAbsolutePath());
  } else if (downloadFile.getName().endsWith(".tar.gz")) {
    final TarGZipUnArchiver unarchiver = new TarGZipUnArchiver();
    unarchiver.enableLogging(new ConsoleLogger(Logger.LEVEL_WARN, "Gcloud SDK Unarchive"));
    unarchiver.setSourceFile(downloadFile);
    unarchiver.setDestDirectory(sdkDir);
    unarchiver.extract();
  }
  if (!downloadFile.delete()) {
    LOGGER.warn("cannot delete " + downloadFile.getAbsolutePath());
  }
  // Check the install
  if (!isInstalled()) {
    LOGGER.error("Gcloud install failed");
    return false;
  }

  // Install the beta components
  final File gcloudExe = new File(sdkDir, GCLOUD_EXE_DIR + "/gcloud");

  final CommandLine cmdLine = new CommandLine(gcloudExe);
  cmdLine.addArgument("components");
  cmdLine.addArgument("install");
  cmdLine.addArgument("beta");
  cmdLine.addArgument("--quiet");
  final DefaultExecutor executor = new DefaultExecutor();
  final int exitValue = executor.execute(cmdLine);

  return (exitValue == 0);
}
 
Example #16
Source File: LoggingRule.java    From deadcode4j with Apache License 2.0 4 votes vote down vote up
public LoggingRule() {
    this(new DefaultLog(new ConsoleLogger(Logger.LEVEL_DEBUG, "junit")));
}