Search in sources :

Example 1 with LegacyImporter

use of com.redhat.ceylon.cmr.ceylon.LegacyImporter in project ceylon-compiler by ceylon.

the class CeylonImportJarTool method run.

@Override
public void run() throws Exception {
    LegacyImporter importer = createImporter().moduleDescriptor(applyCwd(descriptor));
    if (!force || updateDescriptor) {
        try {
            importer.loadModuleDescriptor();
        } catch (ImportJarException x) {
            throw x;
        } catch (Exception x) {
            String key = "error.descriptorFile.invalid.";
            if (descriptor.getName().endsWith(".xml")) {
                key += "xml";
            } else {
                key += "properties";
            }
            throw new ImportJarException(key, new Object[] { descriptor.getPath(), x.getMessage() }, x);
        }
        if (!showClasses) {
            importer.listPackages(showSuggestions);
        } else {
            importer.listClasses();
        }
    }
    boolean hasErrors = importer.hasErrors();
    if (importer.hasProblems()) {
        if (updateDescriptor && descriptor != null) {
            if (!dryRun) {
                importer.updateModuleDescriptor();
            }
        } else {
            hasErrors = true;
        }
    }
    if (!hasErrors || force) {
        if (!hasErrors) {
            if (force && !updateDescriptor) {
                msg("info.forcedUpdate");
            } else {
                msg("info.noProblems");
            }
        } else {
            msg("error.problemsFoundForced");
        }
        if (!dryRun) {
            msg("info.noProblems.publishing").newline();
            try {
                importer.publish();
            } catch (RepositoryException x) {
                throw new ImportJarException("error.failedWriteArtifact", new Object[] { module, x.getLocalizedMessage() }, x);
            } catch (Exception x) {
                // FIXME: remove when the whole CMR is using RepositoryException
                throw new ImportJarException("error.failedWriteArtifact", new Object[] { module, x.getLocalizedMessage() }, x);
            }
            String repoString = this.getOutputRepositoryManager().getRepositoriesDisplayString().toString();
            msg("info.published", this.module.toString(), repoString.substring(1, repoString.length() - 1));
        }
        append(".").newline();
    } else {
        String msgKey;
        if (!updateDescriptor && descriptor == null) {
            msgKey = "error.problemsFoundSuggest";
        } else {
            msgKey = "error.problemsFound";
        }
        throw new ToolUsageError(Messages.msg(ImportJarMessages.RESOURCE_BUNDLE, msgKey));
    }
}
Also used : ToolUsageError(com.redhat.ceylon.common.tool.ToolUsageError) RepositoryException(com.redhat.ceylon.model.cmr.RepositoryException) LegacyImporter(com.redhat.ceylon.cmr.ceylon.LegacyImporter) IOException(java.io.IOException) RepositoryException(com.redhat.ceylon.model.cmr.RepositoryException)

Aggregations

LegacyImporter (com.redhat.ceylon.cmr.ceylon.LegacyImporter)1 ToolUsageError (com.redhat.ceylon.common.tool.ToolUsageError)1 RepositoryException (com.redhat.ceylon.model.cmr.RepositoryException)1 IOException (java.io.IOException)1