private InputStream resolveDescriptor()

in enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/ExternalRules.java [83:107]


    private InputStream resolveDescriptor() throws EnforcerRuleError {
        InputStream descriptorStream;
        if (location != null) {
            if (location.startsWith(LOCATION_PREFIX_CLASSPATH)) {
                String classpathLocation = location.substring(LOCATION_PREFIX_CLASSPATH.length());
                getLog().debug("Read rules form classpath location: " + classpathLocation);
                ClassLoader classRealm = mojoExecution.getMojoDescriptor().getRealm();
                descriptorStream = classRealm.getResourceAsStream(classpathLocation);
                if (descriptorStream == null) {
                    throw new EnforcerRuleError("Location '" + classpathLocation + "' not found in classpath");
                }
            } else {
                File descriptorFile = evaluator.alignToBaseDirectory(new File(location));
                getLog().debug("Read rules form file location: " + descriptorFile);
                try {
                    descriptorStream = Files.newInputStream(descriptorFile.toPath());
                } catch (IOException e) {
                    throw new EnforcerRuleError("Could not read descriptor in " + descriptorFile, e);
                }
            }
        } else {
            throw new EnforcerRuleError("No location provided");
        }
        return descriptorStream;
    }