use of org.gradle.api.GradleException in project gradle by gradle.
the class GitVersionControlSystem method getRemoteForUrl.
// This method is only necessary until https://bugs.eclipse.org/bugs/show_bug.cgi?id=525300 is fixed.
private static String getRemoteForUrl(Repository repository, URI url) throws URISyntaxException {
Config config = repository.getConfig();
Set<String> remotes = config.getSubsections("remote");
Set<String> foundUrls = new HashSet<String>();
String normalizedUrl = normalizeUri(url);
for (String remote : remotes) {
String remoteUrl = config.getString("remote", remote, "url");
if (remoteUrl.equals(normalizedUrl)) {
return remote;
} else {
foundUrls.add(remoteUrl);
}
}
throw new GradleException(String.format("Could not find remote with url: %s. Found: %s", url, foundUrls));
}
use of org.gradle.api.GradleException in project gradle by gradle.
the class DefaultScriptCompilationHandler method compileToDir.
@Override
public void compileToDir(ScriptSource source, ClassLoader classLoader, File classesDir, File metadataDir, CompileOperation<?> extractingTransformer, Class<? extends Script> scriptBaseClass, Action<? super ClassNode> verifier) {
Timer clock = Time.startTimer();
GFileUtils.deleteDirectory(classesDir);
GFileUtils.mkdirs(classesDir);
CompilerConfiguration configuration = createBaseCompilerConfiguration(scriptBaseClass);
configuration.setTargetDirectory(classesDir);
try {
compileScript(source, classLoader, configuration, metadataDir, extractingTransformer, verifier);
} catch (GradleException e) {
GFileUtils.deleteDirectory(classesDir);
GFileUtils.deleteDirectory(metadataDir);
throw e;
}
logger.debug("Timing: Writing script to cache at {} took: {}", classesDir.getAbsolutePath(), clock.getElapsed());
}
use of org.gradle.api.GradleException in project gradle by gradle.
the class DefaultScriptCompilationHandler method compileScript.
private void compileScript(final ScriptSource source, ClassLoader classLoader, CompilerConfiguration configuration, File metadataDir, final CompileOperation<?> extractingTransformer, final Action<? super ClassNode> customVerifier) {
final Transformer transformer = extractingTransformer != null ? extractingTransformer.getTransformer() : null;
logger.info("Compiling {} using {}.", source.getDisplayName(), transformer != null ? transformer.getClass().getSimpleName() : "no transformer");
final EmptyScriptDetector emptyScriptDetector = new EmptyScriptDetector();
final PackageStatementDetector packageDetector = new PackageStatementDetector();
GroovyClassLoader groovyClassLoader = new GroovyClassLoader(classLoader, configuration, false) {
@Override
protected CompilationUnit createCompilationUnit(CompilerConfiguration compilerConfiguration, CodeSource codeSource) {
CompilationUnit compilationUnit = new CustomCompilationUnit(source, compilerConfiguration, codeSource, customVerifier, this);
if (transformer != null) {
transformer.register(compilationUnit);
}
compilationUnit.addPhaseOperation(packageDetector, Phases.CANONICALIZATION);
compilationUnit.addPhaseOperation(emptyScriptDetector, Phases.CANONICALIZATION);
return compilationUnit;
}
};
groovyClassLoader.setResourceLoader(NO_OP_GROOVY_RESOURCE_LOADER);
String scriptText = source.getResource().getText();
String scriptName = source.getClassName();
GroovyCodeSource codeSource = new GroovyCodeSource(scriptText == null ? "" : scriptText, scriptName, "/groovy/script");
try {
try {
groovyClassLoader.parseClass(codeSource, false);
} catch (MultipleCompilationErrorsException e) {
wrapCompilationFailure(source, e);
} catch (CompilationFailedException e) {
throw new GradleException(String.format("Could not compile %s.", source.getDisplayName()), e);
}
if (packageDetector.hasPackageStatement) {
throw new UnsupportedOperationException(String.format("%s should not contain a package statement.", StringUtils.capitalize(source.getDisplayName())));
}
serializeMetadata(source, extractingTransformer, metadataDir, emptyScriptDetector.isEmptyScript(), emptyScriptDetector.getHasMethods());
} finally {
ClassLoaderUtils.tryClose(groovyClassLoader);
}
}
use of org.gradle.api.GradleException in project gradle by gradle.
the class TarCopyAction method execute.
public WorkResult execute(final CopyActionProcessingStream stream) {
final OutputStream outStr;
try {
outStr = compressor.createArchiveOutputStream(tarFile);
} catch (Exception e) {
throw new GradleException(String.format("Could not create TAR '%s'.", tarFile), e);
}
IoActions.withResource(outStr, new ErroringAction<OutputStream>() {
@Override
protected void doExecute(final OutputStream outStr) throws Exception {
TarOutputStream tarOutStr;
try {
tarOutStr = new TarOutputStream(outStr);
} catch (Exception e) {
throw new GradleException(String.format("Could not create TAR '%s'.", tarFile), e);
}
tarOutStr.setLongFileMode(TarOutputStream.LONGFILE_GNU);
stream.process(new StreamAction(tarOutStr));
tarOutStr.close();
}
});
return WorkResults.didWork(true);
}
use of org.gradle.api.GradleException in project gradle by gradle.
the class ZipFileTree method visit.
public void visit(FileVisitor visitor) {
if (!zipFile.exists()) {
throw new InvalidUserDataException(String.format("Cannot expand %s as it does not exist.", getDisplayName()));
}
if (!zipFile.isFile()) {
throw new InvalidUserDataException(String.format("Cannot expand %s as it is not a file.", getDisplayName()));
}
AtomicBoolean stopFlag = new AtomicBoolean();
try {
ZipFile zip = new ZipFile(zipFile);
File expandedDir = getExpandedDir();
try {
// The iteration order of zip.getEntries() is based on the hash of the zip entry. This isn't much use
// to us. So, collect the entries in a map and iterate over them in alphabetical order.
Map<String, ZipEntry> entriesByName = new TreeMap<String, ZipEntry>();
Enumeration entries = zip.getEntries();
while (entries.hasMoreElements()) {
ZipEntry entry = (ZipEntry) entries.nextElement();
entriesByName.put(entry.getName(), entry);
}
Iterator<ZipEntry> sortedEntries = entriesByName.values().iterator();
while (!stopFlag.get() && sortedEntries.hasNext()) {
ZipEntry entry = sortedEntries.next();
if (entry.isDirectory()) {
visitor.visitDir(new DetailsImpl(zipFile, expandedDir, entry, zip, stopFlag, chmod));
} else {
visitor.visitFile(new DetailsImpl(zipFile, expandedDir, entry, zip, stopFlag, chmod));
}
}
} finally {
zip.close();
}
} catch (Exception e) {
throw new GradleException(String.format("Could not expand %s.", getDisplayName()), e);
}
}
Aggregations