private void ensureSaveDir(String fileName) throws MojoExecutionException { File saveDir = new File(fileName).getParentFile(); if (!saveDir.exists()) { if (!saveDir.mkdirs()) { throw new MojoExecutionException("Can not create directory " + saveDir + " for storing save file"); } } }
@Nonnull protected File ensureDockerInfoDirectory() throws MojoExecutionException { if (!dockerInfoDirectory.exists()) { if (!dockerInfoDirectory.mkdirs()) { throw new MojoExecutionException( MessageFormat .format("Could not create Docker info directory {0}", dockerInfoDirectory)); } } return dockerInfoDirectory; }
/** * Resolves the path for this SDK. * * @return a <code>File</code> pointing to the SDk Directory. * @throws org.apache.maven.plugin.MojoExecutionException * if the file can not be resolved. */ public File getSdkPath() throws MojoExecutionException { if ( sdkPath.exists() ) { return sdkPath; } throw new MojoExecutionException( "Can't find the SDK directory : " + sdkPath.getAbsolutePath() ); }
private File createArchiveDir(BuildDirs dirs) throws IOException, MojoExecutionException { File archiveDir = new File(dirs.getTemporaryRootDirectory(), "changed-files"); if (archiveDir.exists()) { // Remove old stuff to FileUtils.cleanDirectory(archiveDir); } else { if (!archiveDir.mkdir()) { throw new MojoExecutionException("Cannot create " + archiveDir); } } return archiveDir; }
private File getSaturnExecutorZip(IvyGetArtifact ivyGetArtifact, String saturnVersion) throws MojoExecutionException { Set<Map<String, Object>> executorArtifacts = new HashSet<Map<String, Object>>(); Map<String, Object> executorZip = new HashMap<String, Object>(); executorZip.put("name", "saturn-executor"); executorZip.put("type", "zip"); executorZip.put("ext", "zip"); executorArtifacts.add(executorZip); Map<String, String> extraAttributes = new HashMap<String, String>(); extraAttributes.put("m:classifier", "zip"); executorZip.put("extraAttributes", extraAttributes); List<URL> executorURLs = null; try { executorURLs = ivyGetArtifact.get("com.vip.saturn", "saturn-executor", saturnVersion, new String[] { "master(*)" }, executorArtifacts); } catch (Exception e) { e.printStackTrace(); throw new MojoExecutionException("download saturn-executor failed", e); } if (executorURLs == null || executorURLs.isEmpty()) { throw new MojoExecutionException("download saturn-executor failed"); } return new File(executorURLs.get(0).getFile()); }
File sourceFile = new File( parsedSource ); final String destinationPath; if ( parsedDestination.endsWith( "/" ) ) final String sourcePath = sourceFile.getAbsolutePath(); result.put( sourcePath, destinationPath ); String filePath = file.getAbsolutePath().substring( sourceFile.getAbsolutePath().length() ); filePath = filePath.replace( System.getProperty( "file.separator" ), "/" ); result.put( file.getAbsolutePath(), destinationPath + filePath ); throw new MojoExecutionException( "Cannot execute push goal: File or directory " + sourceFile.getAbsolutePath() + " does not exist." );
private void generateBuildConfigForPackage( String packageName ) throws MojoExecutionException getLog().debug( "Creating BuildConfig for " + packageName ); File outputFolder = new File( genDirectory, packageName.replace( ".", File.separator ) ); outputFolder.mkdirs(); File outputFile = new File( outputFolder, "BuildConfig.java" ); try throw new MojoExecutionException( "Error generating BuildConfig", e );
private void copyFolder( File sourceFolder, File targetFolder, FileFilter filter ) throws MojoExecutionException { if ( !sourceFolder.exists() ) { return; } try { getLog().debug( "Copying " + sourceFolder + " to " + targetFolder ); if ( ! targetFolder.exists() ) { if ( ! targetFolder.mkdirs() ) { throw new MojoExecutionException( "Could not create target directory " + targetFolder ); } } FileUtils.copyDirectory( sourceFolder, targetFolder, filter ); } catch ( IOException e ) { throw new MojoExecutionException( "Could not copy source folder to target folder", e ); } }
private void copyNativeLibraryArtifact( Artifact artifact, File destinationDirectory, String ndkArchitecture ) throws MojoExecutionException { final File artifactFile = getArtifactResolverHelper().resolveArtifactToFile( artifact ); try { final String artifactId = artifact.getArtifactId(); String filename = artifactId.startsWith( "lib" ) ? artifactId + ".so" : "lib" + artifactId + ".so"; if ( ndkFinalLibraryName != null && artifact.getFile().getName().startsWith( "lib" + ndkFinalLibraryName ) ) { // The artifact looks like one we built with the NDK in this module // preserve the name from the NDK build filename = artifact.getFile().getName(); } final File folder = new File( destinationDirectory, ndkArchitecture ); final File file = new File( folder, filename ); getLog().debug( "Copying native dependency " + artifactId + " (" + artifact.getGroupId() + ") to " + file ); FileUtils.copyFile( artifactFile, file ); } catch ( IOException e ) { throw new MojoExecutionException( "Could not copy native dependency.", e ); } }
@SuppressWarnings({ "unchecked" }) @Override public void execute() throws MojoExecutionException, MojoFailureException { if (!CommonUtils.initSaturnHome()) throw new MojoExecutionException("The ${user.home}/.saturn/caches is not exists"); Log log = getLog(); MavenProject project = (MavenProject) getPluginContext().get("project"); String version = getSaturnVersion(project); log.info("Packing the saturn job into a zip file: version:" + version); List<File> runtimeLibFiles = new ArrayList<File>(); List<Artifact> runtimeArtifacts = project.getRuntimeArtifacts(); for (Artifact artifact : runtimeArtifacts) { runtimeLibFiles.add(artifact.getFile()); } runtimeLibFiles.add(new File(project.getBuild().getDirectory(), project.getBuild().getFinalName() + "." + project.getPackaging())); File zipFile = new File(project.getBuild().getDirectory(), project.getArtifactId() + "-" + project.getVersion() + "-" + "app.zip"); try { CommonUtils.zip(runtimeLibFiles, null, zipFile); } catch (Exception e) { e.printStackTrace(); throw new MojoExecutionException("zip " + zipFile + " failed", e); } projectHelper.attachArtifact(project, "zip", "executor", zipFile); }
@Override public void execute(Speedment speedment) throws MojoExecutionException, MojoFailureException { getLog().info("Generating code using JSON configuration file: '" + configLocation().toAbsolutePath() + "'."); if (hasConfigFile()) { try { final Project project = speedment.getOrThrow(ProjectComponent.class).getProject(); speedment.getOrThrow(TranslatorManager.class).accept(project); // after generating the speedment code, the package location needs to be added as a source folder if (!mavenProject.getCompileSourceRoots().contains(mavenProject.getBasedir().getAbsolutePath() + "/" + project.getPackageLocation())) { System.out.println("adding new source location"); mavenProject.addCompileSourceRoot(mavenProject.getBasedir().getAbsolutePath() + "/" + project.getPackageLocation()); } } catch (final Exception ex) { final String err = "Error parsing configFile file."; LOGGER.error(ex, err); getLog().error(err); throw new MojoExecutionException(err, ex); } } else { final String err = "To run speedment:generate a valid configFile needs to be specified."; getLog().error(err); throw new MojoExecutionException(err); } }
private byte[] doEnhancement(File javaClassFile, Enhancer enhancer) throws MojoExecutionException { try { String className = javaClassFile.getAbsolutePath().substring( base.length() + 1, javaClassFile.getAbsolutePath().length() - ".class".length() ).replace( File.separatorChar, '.' ); ByteArrayOutputStream originalBytes = new ByteArrayOutputStream(); FileInputStream fileInputStream = new FileInputStream( javaClassFile ); try { byte[] buffer = new byte[1024]; int length; while ( ( length = fileInputStream.read( buffer ) ) != -1 ) { originalBytes.write( buffer, 0, length ); } } finally { fileInputStream.close(); } return enhancer.enhance( className, originalBytes.toByteArray() ); } catch (Exception e) { String msg = "Unable to enhance class: " + javaClassFile.getName(); if ( failOnError ) { throw new MojoExecutionException( msg, e ); } buildContext.addMessage( javaClassFile, 0, 0, msg, BuildContext.SEVERITY_WARNING, e ); return null; } }
try { urls.add( file.toURI().toURL() ); getLog().debug( "Adding classpath entry for classes root " + file.getAbsolutePath() ); String msg = "Unable to resolve classpath entry to URL: " + file.getAbsolutePath(); if ( failOnError ) { throw new MojoExecutionException( msg, e ); try { urls.add( a.getFile().toURI().toURL() ); getLog().debug( "Adding classpath entry for dependency " + a.getId() ); String msg = "Unable to resolve URL for dependency " + a.getId() + " at " + a.getFile().getAbsolutePath(); if ( failOnError ) { throw new MojoExecutionException( msg, e );
@Nullable protected String readMetadata(@Nonnull Metadata metadata) throws MojoExecutionException { final File metadataFile = ensureMetadataFile(metadata); if (!metadataFile.exists()) { return null; } try { return Files.readFirstLine(metadataFile, Charsets.UTF_8); } catch (IOException e) { final String message = MessageFormat.format("Could not read {0} file at {1}", metadata.getFileName(), metadataFile); throw new MojoExecutionException(message, e); } }
@Override protected void execute(Speedment speedment) throws MojoExecutionException, MojoFailureException { getLog().info("Saving default configuration from database to '" + configLocation().toAbsolutePath() + "'."); final ConfigFileHelper helper = speedment.getOrThrow(ConfigFileHelper.class); try { helper.setCurrentlyOpenFile(configLocation().toFile()); helper.loadFromDatabaseAndSaveToFile(); } catch (final Exception ex) { final String err = "An error occured while reloading."; getLog().error(err); throw new MojoExecutionException(err, ex); } }
private void copyLocalNativeLibraries( final File localNativeLibrariesDirectory, final File destinationDirectory ) throws MojoExecutionException { getLog().debug( "Copying existing native libraries from " + localNativeLibrariesDirectory ); try { IOFileFilter libSuffixFilter = FileFilterUtils.suffixFileFilter( ".so" ); IOFileFilter gdbserverNameFilter = FileFilterUtils.nameFileFilter( "gdbserver" ); IOFileFilter orFilter = FileFilterUtils.or( libSuffixFilter, gdbserverNameFilter ); IOFileFilter libFiles = FileFilterUtils.and( FileFileFilter.FILE, orFilter ); FileFilter filter = FileFilterUtils.or( DirectoryFileFilter.DIRECTORY, libFiles ); org.apache.commons.io.FileUtils .copyDirectory( localNativeLibrariesDirectory, destinationDirectory, filter ); } catch ( IOException e ) { getLog().error( "Could not copy native libraries: " + e.getMessage(), e ); throw new MojoExecutionException( "Could not copy native dependency.", e ); } }
public void doWithDevice( final IDevice device ) throws MojoExecutionException { String deviceLogLinePrefix = DeviceHelper.getDeviceLogLinePrefix( device ); try { device.uninstallPackage( packageName ); getLog().info( deviceLogLinePrefix + "Successfully uninstalled " + packageName ); getLog().debug( " from " + DeviceHelper.getDescriptiveName( device ) ); result.set( true ); } catch ( InstallException e ) { result.set( false ); throw new MojoExecutionException( deviceLogLinePrefix + "Uninstall of " + packageName + " failed.", e ); } } } );
private void writeTestMetadata() throws MojoExecutionException { if (writeTestMetadata && dockerInfoDirectory.exists()) { final File testMetadataDir = new File(testOutputDirectory, getMetaSubdir()); if (!testMetadataDir.isDirectory()) { if (!testMetadataDir.mkdirs()) { throw new MojoExecutionException("Could not create metadata output directory"); } } for (String name : dockerInfoDirectory.list()) { final File sourceFile = new File(dockerInfoDirectory, name); final File targetFile = new File(testMetadataDir, name); try { Files.copy(sourceFile, targetFile); } catch (IOException e) { throw new MojoExecutionException("Could not copy files", e); } } } }
protected void alertAndStopExecutionIfDirectoryWithCompiledClassesOfThisProjectDoesNotExist( String directoryWithCompiledClassesOfThisProject) throws MojoExecutionException { File classesDir = null; if (directoryWithCompiledClassesOfThisProject != null) { classesDir = new File(directoryWithCompiledClassesOfThisProject); } if (classesDir == null || !classesDir.exists()) { getLog().error("Directory with classes does not exist: " + directoryWithCompiledClassesOfThisProject); getLog().error("Maybe running 'mvn compile' before running 'mvn ninja:run' helps :)"); // BAM! //System.exit(1); throw new MojoExecutionException("Directory with classes does not exist: " + directoryWithCompiledClassesOfThisProject); } } }
@SuppressWarnings("unchecked") protected final ClassLoader getClassLoader() throws MojoExecutionException, DependencyResolutionRequiredException { final MavenProject project = project(); final List<String> classpathElements = new ArrayList<>(); classpathElements.addAll(project.getCompileClasspathElements()); classpathElements.addAll(project.getRuntimeClasspathElements()); classpathElements.add(project.getBuild().getOutputDirectory()); final List<URL> projectClasspathList = new ArrayList<>(); for (final String element : classpathElements) { try { projectClasspathList.add(new File(element).toURI().toURL()); } catch (final MalformedURLException ex) { throw new MojoExecutionException( element + " is an invalid classpath element", ex ); } } return new URLClassLoader( projectClasspathList.toArray(new URL[projectClasspathList.size()]), Thread.currentThread().getContextClassLoader() ); }