All Downloads are FREE. Search and download functionalities are using the official Maven repository.

eu.cedarsoft.devtools.modules.InstallFileToRemoteRepository Maven / Gradle / Ivy

The newest version!
package eu.cedarsoft.devtools.modules;

import com.google.inject.Inject;
import eu.cedarsoft.devtools.CommandLineContext;
import eu.cedarsoft.devtools.FileTools;
import eu.cedarsoft.devtools.MavenMessageHandler;
import eu.cedarsoft.devtools.MavenSupport;
import eu.cedarsoft.devtools.Module;
import eu.cedarsoft.devtools.ProcessWrapper;
import eu.cedarsoft.utils.CmdLine;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;

import java.io.File;

/**
 * Installs a file to a remote repository
 */
public class InstallFileToRemoteRepository implements Module {
  //Todo synchronization?
  @NonNls
  private String lastGroupId = "";
  @NonNls
  private String lastVersion = "";
  @NonNls
  private String lastRepositoryId = "";
  @NonNls
  private String lastRepositoryUlr = "";

  @NotNull
  private final CommandLineContext commandLineContext;
  @NotNull
  private final MavenSupport mavenSupport;

  @Inject
  public InstallFileToRemoteRepository( @NotNull MavenSupport mavenSupport, @NotNull CommandLineContext commandLineContext ) {
    this.mavenSupport = mavenSupport;
    this.commandLineContext = commandLineContext;
  }

  @NotNull
  public String getDescription() {
    return MavenMessageHandler.get( "module.install.file.to.remote" );
  }

  public void process( @NotNull CmdLine cmdLine ) throws Exception {
    while ( true ) {
      cmdLine.out( MavenMessageHandler.get( "install.file.remote" ) );

      File jarToImport = FileTools.readFile( cmdLine, MavenMessageHandler.get( "select.jar.file" ), "jar" );

      String groupId = cmdLine.read( MavenMessageHandler.get( "select.group.id" ), lastGroupId );
      lastGroupId = groupId;

      @NonNls
      String suggestedArtifactId = InstallFileToRepository.suggestArtifactId( jarToImport.getName() );
      @NonNls
      String artifactId = cmdLine.read( MavenMessageHandler.get( "select.artifact.id" ), suggestedArtifactId );
      @NonNls
      String version = cmdLine.read( MavenMessageHandler.get( "select.version" ), lastVersion );
      lastVersion = version;

      //Now ask for the repository
      @NonNls String repositoryId = cmdLine.read( MavenMessageHandler.get( "select.repository.id" ), lastRepositoryId );

      //And its URL
      @NonNls String repositoryUrl = cmdLine.read( MavenMessageHandler.get( "select.repository.url" ), lastRepositoryUlr );


      cmdLine.warning( MavenMessageHandler.get( "install.file.remote" ) );
      cmdLine.success( '\t' + jarToImport.getCanonicalPath() );

      cmdLine.out( MavenMessageHandler.get( "with.groupId" ) );
      cmdLine.success( '\t' + groupId );

      cmdLine.out( MavenMessageHandler.get( "with.artifactId" ) );
      cmdLine.success( '\t' + artifactId );

      cmdLine.out( MavenMessageHandler.get( "with.version" ) );
      cmdLine.success( '\t' + version );

      cmdLine.out( MavenMessageHandler.get( "to.repository" ) );
      cmdLine.success( '\t' + repositoryId + ": " + repositoryUrl );

      cmdLine.pause( 2 );

      @NonNls String command = mavenSupport.getMavenBin() + " deploy:deploy-file -DgeneratePom=true -Dpackaging=jar -Dfile=" + jarToImport.getName() + " " +
          " -D" + MavenSupport.GROUP_ID + "=" + groupId + " -D" + MavenSupport.ARTIFACT_ID + "=" + artifactId + " -D" + MavenSupport.VERSION + "=" + version + commandLineContext.getCmdLineArgs() + " -DrepositoryId=" + repositoryId
          + " -Durl=" + repositoryUrl;

      ProcessWrapper.runCommand( cmdLine, command );
      cmdLine.success( MavenMessageHandler.get( "module.processed.successfully" ) );
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy