Search in sources :

Example 16 with InvalidUserDataException

use of org.gradle.api.InvalidUserDataException in project atlas by alibaba.

the class PublishToMavenRepositoryHook method publish.

@TaskAction
public void publish() {
    MavenPublicationInternal publicationInternal = getPublicationInternal();
    if (publicationInternal == null) {
        throw new InvalidUserDataException("The 'publication' property is required");
    }
    MavenArtifactRepository repository = getRepository();
    if (repository == null) {
        throw new InvalidUserDataException("The 'repository' property is required");
    }
    doPublish(publicationInternal, repository);
}
Also used : InvalidUserDataException(org.gradle.api.InvalidUserDataException) MavenArtifactRepository(org.gradle.api.artifacts.repositories.MavenArtifactRepository) MavenPublicationInternal(org.gradle.api.publish.maven.internal.publication.MavenPublicationInternal) TaskAction(org.gradle.api.tasks.TaskAction)

Example 17 with InvalidUserDataException

use of org.gradle.api.InvalidUserDataException in project zaproxy by zaproxy.

the class CreateGitHubRelease method createRelease.

@TaskAction
public void createRelease() throws IOException {
    if (bodyFile.isPresent() && body.isPresent()) {
        throw new InvalidUserDataException("Only one type of body property must be set.");
    }
    if (checksumAlgorithm.get().isEmpty()) {
        throw new IllegalArgumentException("The checksum algorithm must not be empty.");
    }
    GitHubUser ghUser = getUser().get();
    GHRepository ghRepo = GitHub.connect(ghUser.getName(), ghUser.getAuthToken()).getRepository(repo.get());
    validateTagExists(ghRepo, tag.get());
    validateReleaseDoesNotExist(ghRepo, tag.get());
    StringBuilder releaseBody = new StringBuilder(250);
    releaseBody.append(bodyFile.isPresent() ? readContents(bodyFile.getAsFile().get().toPath()) : body.getOrElse(""));
    if (addChecksums.get()) {
        if (releaseBody.length() != 0) {
            releaseBody.append("\n\n---\n");
        }
        appendChecksumsTable(releaseBody);
    }
    GHRelease release = ghRepo.createRelease(tag.get()).name(title.get()).body(releaseBody.toString()).prerelease(prerelease.get()).draft(true).create();
    for (Asset asset : assets) {
        release.uploadAsset(asset.getFile().getAsFile().get(), asset.getContentType().get());
    }
    if (!draft.get()) {
        release.update().draft(false).update();
    }
}
Also used : GitHubUser(org.zaproxy.zap.GitHubUser) GHRepository(org.kohsuke.github.GHRepository) InvalidUserDataException(org.gradle.api.InvalidUserDataException) GHRelease(org.kohsuke.github.GHRelease) TaskAction(org.gradle.api.tasks.TaskAction)

Example 18 with InvalidUserDataException

use of org.gradle.api.InvalidUserDataException in project spring-boot by spring-projects.

the class UpgradeBom method upgradeDependencies.

@TaskAction
@SuppressWarnings("deprecation")
void upgradeDependencies() {
    GitHubRepository repository = createGitHub().getRepository(this.bom.getUpgrade().getGitHub().getOrganization(), this.bom.getUpgrade().getGitHub().getRepository());
    List<String> availableLabels = repository.getLabels();
    List<String> issueLabels = this.bom.getUpgrade().getGitHub().getIssueLabels();
    if (!availableLabels.containsAll(issueLabels)) {
        List<String> unknownLabels = new ArrayList<>(issueLabels);
        unknownLabels.removeAll(availableLabels);
        throw new InvalidUserDataException("Unknown label(s): " + StringUtils.collectionToCommaDelimitedString(unknownLabels));
    }
    Milestone milestone = determineMilestone(repository);
    List<Issue> existingUpgradeIssues = repository.findIssues(issueLabels, milestone);
    List<Upgrade> upgrades = new InteractiveUpgradeResolver(new MavenMetadataVersionResolver(this.repositoryUrls), this.bom.getUpgrade().getPolicy(), getServices().get(UserInputHandler.class)).resolveUpgrades(this.bom.getLibraries());
    Path buildFile = getProject().getBuildFile().toPath();
    Path gradleProperties = new File(getProject().getRootProject().getProjectDir(), "gradle.properties").toPath();
    UpgradeApplicator upgradeApplicator = new UpgradeApplicator(buildFile, gradleProperties);
    for (Upgrade upgrade : upgrades) {
        String title = "Upgrade to " + upgrade.getLibrary().getName() + " " + upgrade.getVersion();
        Issue existingUpgradeIssue = findExistingUpgradeIssue(existingUpgradeIssues, upgrade);
        if (existingUpgradeIssue != null) {
            System.out.println(title + " (supersedes #" + existingUpgradeIssue.getNumber() + " " + existingUpgradeIssue.getTitle() + ")");
        } else {
            System.out.println(title);
        }
        try {
            Path modified = upgradeApplicator.apply(upgrade);
            int issueNumber = repository.openIssue(title, (existingUpgradeIssue != null) ? "Supersedes #" + existingUpgradeIssue.getNumber() : "", issueLabels, milestone);
            if (existingUpgradeIssue != null) {
                existingUpgradeIssue.label(Arrays.asList("type: task", "status: superseded"));
            }
            if (new ProcessBuilder().command("git", "add", modified.toFile().getAbsolutePath()).start().waitFor() != 0) {
                throw new IllegalStateException("git add failed");
            }
            if (new ProcessBuilder().command("git", "commit", "-m", title + "\n\nCloses gh-" + issueNumber).start().waitFor() != 0) {
                throw new IllegalStateException("git commit failed");
            }
        } catch (IOException ex) {
            throw new TaskExecutionException(this, ex);
        } catch (InterruptedException ex) {
            Thread.currentThread().interrupt();
        }
    }
}
Also used : Path(java.nio.file.Path) Issue(org.springframework.boot.build.bom.bomr.github.Issue) Milestone(org.springframework.boot.build.bom.bomr.github.Milestone) ArrayList(java.util.ArrayList) IOException(java.io.IOException) GitHubRepository(org.springframework.boot.build.bom.bomr.github.GitHubRepository) TaskExecutionException(org.gradle.api.tasks.TaskExecutionException) InvalidUserDataException(org.gradle.api.InvalidUserDataException) File(java.io.File) TaskAction(org.gradle.api.tasks.TaskAction)

Example 19 with InvalidUserDataException

use of org.gradle.api.InvalidUserDataException in project gradle by gradle.

the class MapNotationConverter method parseType.

@Override
public T parseType(Map values) throws UnsupportedNotationException {
    Map<String, Object> mutableValues = new HashMap<>(Cast.uncheckedNonnullCast(values));
    Set<String> missing = null;
    ConvertMethod convertMethod = null;
    Method method = null;
    while (method == null) {
        convertMethod = ConvertMethod.of(this.getClass());
        // since we need access to the method and that it's weakly referenced
        // we always need to double check that it hasn't been collected
        method = convertMethod.getMethod();
    }
    Class<?>[] parameterTypes = method.getParameterTypes();
    Object[] params = new Object[parameterTypes.length];
    String[] keyNames = convertMethod.keyNames;
    boolean[] optionals = convertMethod.nullables;
    for (int i = 0; i < params.length; i++) {
        String keyName = keyNames[i];
        boolean optional = optionals[i];
        Class<?> type = parameterTypes[i];
        Object value;
        if (type == String.class) {
            value = get(mutableValues, keyName);
        } else {
            value = type.cast(mutableValues.get(keyName));
        }
        if (!optional && value == null) {
            if (missing == null) {
                missing = new TreeSet<>();
            }
            missing.add(keyName);
        }
        mutableValues.remove(keyName);
        params[i] = value;
    }
    if (missing != null) {
        // Throwing InvalidUserDataException here means that useful context information (including candidate formats, etc.) is not presented to the user
        throw new InvalidUserDataException(String.format("Required keys %s are missing from map %s.", missing, values));
    }
    T result;
    try {
        result = Cast.uncheckedNonnullCast(method.invoke(this, params));
    } catch (IllegalAccessException e) {
        throw UncheckedException.throwAsUncheckedException(e);
    } catch (InvocationTargetException e) {
        throw UncheckedException.unwrapAndRethrow(e);
    }
    ConfigureUtil.configureByMap(mutableValues, result);
    return result;
}
Also used : HashMap(java.util.HashMap) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvalidUserDataException(org.gradle.api.InvalidUserDataException)

Example 20 with InvalidUserDataException

use of org.gradle.api.InvalidUserDataException in project gradle by gradle.

the class SelectorState method trackDetailsForOverrideMetadata.

private void trackDetailsForOverrideMetadata(DependencyState dependencyState) {
    ClientModule nextClientModule = DefaultComponentOverrideMetadata.extractClientModule(dependencyState.getDependency());
    if (nextClientModule != null && !nextClientModule.equals(clientModule)) {
        if (clientModule == null) {
            clientModule = nextClientModule;
        } else {
            throw new InvalidUserDataException(dependencyState.getDependency().getSelector().getDisplayName() + " has more than one client module definitions.");
        }
    }
    changing = changing || dependencyState.getDependency().isChanging();
}
Also used : InvalidUserDataException(org.gradle.api.InvalidUserDataException) ClientModule(org.gradle.api.artifacts.ClientModule)

Aggregations

InvalidUserDataException (org.gradle.api.InvalidUserDataException)61 File (java.io.File)18 Task (org.gradle.api.Task)6 ArrayList (java.util.ArrayList)5 LinkedHashSet (java.util.LinkedHashSet)5 Action (org.gradle.api.Action)5 TaskAction (org.gradle.api.tasks.TaskAction)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 DefaultTask (org.gradle.api.DefaultTask)4 ImmutableList (com.google.common.collect.ImmutableList)3 Closure (groovy.lang.Closure)3 Map (java.util.Map)3 MavenArtifactRepository (org.gradle.api.artifacts.repositories.MavenArtifactRepository)3 TaskInternal (org.gradle.api.internal.TaskInternal)3 MavenPublicationInternal (org.gradle.api.publish.maven.internal.publication.MavenPublicationInternal)3 DirectorySensitivity (org.gradle.internal.fingerprint.DirectorySensitivity)3 LineEndingSensitivity (org.gradle.internal.fingerprint.LineEndingSensitivity)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 Nullable (javax.annotation.Nullable)2