private ClassLoader toClassLoader(FileCollection runtimeClasspath) { List<URL> urls = new ArrayList<URL>(); for ( File file : runtimeClasspath ) { try { urls.add( file.toURI().toURL() ); logger.debug( "Adding classpath entry for " + file.getAbsolutePath() ); } catch (MalformedURLException e) { throw new GradleException( "Unable to resolve classpath entry to URL : " + file.getAbsolutePath(), e ); } } return new URLClassLoader( urls.toArray( new URL[urls.size()] ), Enhancer.class.getClassLoader() ); }
private byte[] doEnhancement(File root, File javaClassFile, Enhancer enhancer) { try { String className = javaClassFile.getAbsolutePath().substring( root.getAbsolutePath().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) { throw new GradleException( "Unable to enhance class : " + javaClassFile, e ); } }
throw new GradleException( "Error writing to enhanced class [" + file.getName() + "] to file [" + file.getAbsolutePath() + "]", e ); throw new GradleException( "Error opening class file for writing : " + file.getAbsolutePath(), e );
throw new GradleException("Couldn't find schema files for the variant " + Utils.capitalize(variant) + ". Please" + " ensure a valid schema.json exists under the varian't source sets"); throw new GradleException("Found an ancestor directory to a schema file that contains another schema file." + " Please ensure no schema files exist on the path to another one");
throw new GradleException("Provided schema file path doesn't exists: " + schemaFilePath + ". Please ensure a valid schema file exists"); if (schemaFile != null) { if (outputPackageName == null || outputPackageName.trim().isEmpty()) { throw new GradleException("Missing explicit outputPackageName option. Please ensure a valid package name is provided"); } else { targetPackageFolder = new File(outputFolder.getAbsolutePath()
private void verifyGradleVersion() { if (GradleVersion.current().compareTo(GradleVersion.version("4.4")) < 0) { throw new GradleException("SOFA Boot plugin requires Gradle 4.4 or later." + " The current version is " + GradleVersion.current()); } }
@SuppressWarnings("unchecked") private <T extends FormatExtension> T maybeCreate(String name, Class<T> clazz) { FormatExtension existing = formats.get(name); if (existing != null) { if (!existing.getClass().equals(clazz)) { throw new GradleException("Tried to add format named '" + name + "'" + " of type " + clazz + " but one has already been created of type " + existing.getClass()); } else { return (T) existing; } } else { try { Constructor<T> constructor = clazz.getConstructor(SpotlessExtension.class); T newlyCreated = constructor.newInstance(this); formats.put(name, newlyCreated); return newlyCreated; } catch (NoSuchMethodException e) { throw new GradleException("Must have a constructor " + clazz.getSimpleName() + "(SpotlessExtension root)", e); } catch (Exception e) { throw Errors.asRuntime(e); } } } }
/** Replaces the given step. */ protected void replaceStep(FormatterStep replacementStep) { FormatterStep existing = getExistingStep(replacementStep.getName()); if (existing == null) { throw new GradleException("Cannot replace step '" + replacementStep.getName() + "' for spotless format '" + formatName() + "' because it hasn't been added yet."); } int index = steps.indexOf(existing); steps.set(index, replacementStep); }
/** Adds a new step. */ public void addStep(FormatterStep newStep) { Objects.requireNonNull(newStep); FormatterStep existing = getExistingStep(newStep.getName()); if (existing != null) { throw new GradleException("Multiple steps with name '" + newStep.getName() + "' for spotless format '" + formatName() + "'"); } steps.add(newStep); }
static GradleException youShouldTurnOnPaddedCell(SpotlessTask task) { Path rootPath = task.getProject().getRootDir().toPath(); return new GradleException(StringPrinter.buildStringFromLines( "You have a misbehaving rule which can't make up its mind.", "This means that spotlessCheck will fail even after spotlessApply has run.", "", "This is a bug in a formatting rule, not Spotless itself, but Spotless can", "work around this bug and generate helpful bug reports for the broken rule", "if you add 'paddedCell()' to your build.gradle as such: ", "", " spotless {", " format 'someFormat', {", " ...", " paddedCell()", " }", " }", "", "The next time you run spotlessCheck, it will put helpful bug reports into", "'" + rootPath.relativize(diagnoseDir(task).toPath()) + "', and spotlessApply", "and spotlessCheck will be self-consistent from here on out.", "", "For details see " + URL)); }
@TaskAction public void performAction(IncrementalTaskInputs inputs) throws Exception { if (target == null) { throw new GradleException("You must specify 'Iterable<File> toFormat'"); throw new GradleException("Don't call " + getName() + " directly, call " + getName() + SpotlessPlugin.CHECK + " or " + getName() + SpotlessPlugin.APPLY);
/** Returns an exception which indicates problem files nicely. */ GradleException formatViolationsFor(Formatter formatter, List<File> problemFiles) { return new GradleException(DiffMessageFormatter.builder() .runToFix("Run 'gradlew spotlessApply' to fix these violations.") .isPaddedCell(paddedCell) .formatter(formatter) .problemFiles(problemFiles) .getMessage()); } }
/** If the user hasn't specified the files yet, we'll assume he/she means all of the kotlin files. */ @Override protected void setupTask(SpotlessTask task) { if (target == null) { JavaPluginConvention javaPlugin = getProject().getConvention().findPlugin(JavaPluginConvention.class); if (javaPlugin == null) { throw new GradleException("You must either specify 'target' manually or apply the 'scala' plugin."); } FileCollection union = getProject().files(); for (SourceSet sourceSet : javaPlugin.getSourceSets()) { union = union.plus(sourceSet.getAllSource().filter(file -> { String name = file.getName(); return name.endsWith(".scala") || name.endsWith(".sc"); })); } target = union; } super.setupTask(task); } }
/** If the user hasn't specified the files yet, we'll assume he/she means all of the kotlin files. */ @Override protected void setupTask(SpotlessTask task) { if (target == null) { JavaPluginConvention javaPlugin = getProject().getConvention().findPlugin(JavaPluginConvention.class); if (javaPlugin == null) { throw new GradleException("You must either specify 'target' manually or apply a kotlin plugin."); } FileCollection union = getProject().files(); for (SourceSet sourceSet : javaPlugin.getSourceSets()) { union = union.plus(sourceSet.getAllSource().filter(file -> { String name = file.getName(); return name.endsWith(".kt") || name.endsWith(".kts"); })); } target = union; } super.setupTask(task); } }
private void validateFunctionVersion(final String functionVersion) { if (!functionVersion.matches("[0-9]+")) { throw new GradleException("functionVersion must be a number if usePreviousVersion is true"); } }
/** If the user hasn't specified the files yet, we'll assume he/she means all of the java files. */ @Override protected void setupTask(SpotlessTask task) { if (target == null) { JavaPluginConvention javaPlugin = getProject().getConvention().findPlugin(JavaPluginConvention.class); if (javaPlugin == null) { throw new GradleException("You must apply the java plugin before the spotless plugin if you are using the java extension."); } FileCollection union = getProject().files(); for (SourceSet sourceSet : javaPlugin.getSourceSets()) { union = union.plus(sourceSet.getAllJava()); } target = union; } steps.replaceAll(step -> { if (LicenseHeaderStep.name().equals(step.getName())) { return step.filterByFile(LicenseHeaderStep.unsupportedJvmFilesFilter()); } else { return step; } }); super.setupTask(task); } }
JavaPluginConvention convention = getProject().getConvention().getPlugin(JavaPluginConvention.class); if (convention == null || !getProject().getPlugins().hasPlugin(GroovyBasePlugin.class)) { throw new GradleException("You must apply the groovy plugin before the spotless plugin if you are using the groovy extension.");
private void resolveIfNecessary() { if (!this.importedBoms.isEmpty() && !this.resolved) { try { this.resolved = true; resolve(); } catch (Exception ex) { throw new GradleException("Failed to resolve imported Maven boms: " + getRootCause(ex).getMessage(), ex); } } }
private void validateRequiredProperties() throws GradleException { if (getAdditionalVersionWeight() == null) { throw new GradleException("Additional Version Weight for routing config is required"); } if (getAdditionalVersion() == null && getUsePreviousVersion() == null && getUseNextVersion() == null) { throw new GradleException("Exactly one of AdditionalVersion, UsePreviousVersion, " + "UseNextVersion for routing config is required"); } }
@Override public void dependencySet(Map<String, String> setSpecification, Action<DependencySetHandler> action) { String group = getAsString(setSpecification, KEY_GROUP); String version = getAsString(setSpecification, KEY_VERSION); if (!hasText(group) || !hasText(version)) { throw new GradleException("A dependency set requires both a group and a version"); } configureDependencySet(group, version, action); }