This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to annotated tag org.apache.sling.provisioning.model-1.0.0 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-provisioning-model.git
commit 55e51ed39c72b577c336971779174e3f7a74364f Author: Carsten Ziegeler <cziege...@apache.org> AuthorDate: Wed Oct 1 13:49:29 2014 +0000 Remove old slingstart model git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/tooling/support/slingstart-model@1628703 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/sling/slingstart/model/SSMArtifact.java | 232 ------------------- .../sling/slingstart/model/SSMConfiguration.java | 83 ------- .../sling/slingstart/model/SSMConstants.java | 50 ---- .../sling/slingstart/model/SSMDeliverable.java | 114 ---------- .../apache/sling/slingstart/model/SSMFeature.java | 206 ----------------- .../apache/sling/slingstart/model/SSMMerger.java | 82 ------- .../sling/slingstart/model/SSMStartLevel.java | 80 ------- .../sling/slingstart/model/SSMTraceable.java | 47 ---- .../org/apache/sling/slingstart/model/SSMUtil.java | 194 ---------------- .../sling/slingstart/model/SSMValidator.java | 94 -------- .../sling/slingstart/model/package-info.java | 24 -- .../slingstart/model/txt/TXTSSMModelReader.java | 253 --------------------- .../slingstart/model/txt/TXTSSMModelWriter.java | 203 ----------------- .../sling/slingstart/model/txt/package-info.java | 24 -- 14 files changed, 1686 deletions(-) diff --git a/src/main/java/org/apache/sling/slingstart/model/SSMArtifact.java b/src/main/java/org/apache/sling/slingstart/model/SSMArtifact.java deleted file mode 100644 index 03c473e..0000000 --- a/src/main/java/org/apache/sling/slingstart/model/SSMArtifact.java +++ /dev/null @@ -1,232 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package org.apache.sling.slingstart.model; - -import java.util.HashMap; -import java.util.Map; - -/** - * Description of an artifact. - * An artifact is described by it's Apache Maven coordinates consisting of group id, artifact id, and version. - * In addition, the classifier and type can be specified as well. - * An artifact can have any metadata. - */ -public class SSMArtifact extends SSMTraceable { - - private final String groupId; - private final String artifactId; - private final String version; - private final String classifier; - private final String type; - - private final Map<String, String> metadata = new HashMap<String, String>(); - - /** - * Create a new artifact object - * @param gId The group id (required) - * @param aId The artifact id (required) - * @param version The version (required) - * @param classifier The classifier (optional) - * @param type The type/extension (optional, defaults to jar) - */ - public SSMArtifact(final String gId, - final String aId, - final String version, - final String classifier, - final String type) { - this.groupId = (gId != null ? gId.trim() : null); - this.artifactId = (aId != null ? aId.trim() : null); - this.version = (version != null ? version.trim() : null); - final String trimmedType = (type != null ? type.trim() : null); - if ( "bundle".equals(trimmedType) || trimmedType == null || trimmedType.isEmpty() ) { - this.type = "jar"; - } else { - this.type = trimmedType; - } - final String trimmedClassifier = (classifier != null ? classifier.trim() : null); - if ( trimmedClassifier != null && trimmedClassifier.isEmpty() ) { - this.classifier = null; - } else { - this.classifier = trimmedClassifier; - } - } - - /** - * Create a new artifact from a maven url, - * 'mvn:' [ repository-url '!' ] group-id '/' artifact-id [ '/' [version] [ '/' [type] [ '/' classifier ] ] ] ] - * @param url The url - * @return A new artifact - * @throws IllegalArgumentException If the url is not valid - */ - public static SSMArtifact fromMvnUrl(final String url) { - if ( url == null || !url.startsWith("mvn:") ) { - throw new IllegalArgumentException("Invalid mvn url: " + url); - } - final String content = url.substring(4); - // ignore repository url - int pos = content.indexOf('!'); - if ( pos != -1 ) { - throw new IllegalArgumentException("Repository url is not supported for Maven artifacts at the moment."); - } - final String coordinates = (pos == -1 ? content : content.substring(pos + 1)); - String gId = null; - String aId = null; - String version = null; - String type = null; - String classifier = null; - int part = 0; - String value = coordinates; - while ( value != null ) { - pos = value.indexOf('/'); - final String current; - if ( pos == -1 ) { - current = value; - value = null; - } else { - if ( pos == 0 ) { - current = null; - } else { - current = value.substring(0, pos); - } - value = value.substring(pos + 1); - } - if ( current != null ) { - if ( part == 0 ) { - gId = current; - } else if ( part == 1 ) { - aId = current; - } else if ( part == 2 ) { - version = current; - } else if ( part == 3 ) { - type = current; - } else if ( part == 4 ) { - classifier = current; - } - } - part++; - } - if ( version == null ) { - version = "LATEST"; - } - return new SSMArtifact(gId, aId, version, classifier, type); - } - - /** - * Return a mvn url - * @return A mvn url - * @see #fromMvnUrl(String) - */ - public String toMvnUrl() { - final StringBuilder sb = new StringBuilder("mvn:"); - sb.append(this.groupId); - sb.append('/'); - sb.append(this.artifactId); - sb.append('/'); - sb.append(this.version); - if ( this.classifier != null || !"jar".equals(this.type)) { - sb.append('/'); - sb.append(this.type); - if ( this.classifier != null ) { - sb.append('/'); - sb.append(this.classifier); - } - } - return sb.toString(); - } - - /** - * Return the group id. - * @return The group id. - */ - public String getGroupId() { - return groupId; - } - - /** - * Return the artifact id. - * @return The artifact id. - */ - public String getArtifactId() { - return artifactId; - } - - /** - * Return the version. - * @return The version. - */ - public String getVersion() { - return version; - } - - /** - * Return the optional classifier. - * @return The classifier or null. - */ - public String getClassifier() { - return classifier; - } - - /** - * Return the type. - * @return The type. - */ - public String getType() { - return type; - } - - /** - * Get the metadata of the artifact. - * @return The metadata. - */ - public Map<String, String> getMetadata() { - return this.metadata; - } - - /** - * Create a Maven like relative repository path. - */ - public String getRepositoryPath() { - final StringBuilder sb = new StringBuilder(); - sb.append(groupId.replace('.', '/')); - sb.append('/'); - sb.append(artifactId); - sb.append('/'); - sb.append(version); - sb.append('/'); - sb.append(artifactId); - sb.append('-'); - sb.append(version); - if ( classifier != null ) { - sb.append('-'); - sb.append(classifier); - } - sb.append('.'); - sb.append(type); - return sb.toString(); - } - - @Override - public String toString() { - return "SSMArtifact [groupId=" + groupId - + ", artifactId=" + artifactId - + ", version=" + version - + ", classifier=" + classifier - + ", type=" + type - + ( this.getLocation() != null ? ", location=" + this.getLocation() : "") - + "]"; - } -} diff --git a/src/main/java/org/apache/sling/slingstart/model/SSMConfiguration.java b/src/main/java/org/apache/sling/slingstart/model/SSMConfiguration.java deleted file mode 100644 index f2342e2..0000000 --- a/src/main/java/org/apache/sling/slingstart/model/SSMConfiguration.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package org.apache.sling.slingstart.model; - -import java.util.Dictionary; -import java.util.Hashtable; - - -/** - * Configuration - */ -public class SSMConfiguration extends SSMTraceable { - - private final String pid; - - private final String factoryPid; - - private final Dictionary<String, Object> properties = new Hashtable<String, Object>(); - - public SSMConfiguration(final String pid, final String factoryPid) { - this.pid = (pid != null ? pid.trim() : null); - this.factoryPid = (factoryPid != null ? factoryPid.trim() : null); - } - - /** - * Get the pid. - * If this is a factory configuration, it returns the alias for the configuration - * @return The pid. - */ - public String getPid() { - return this.pid; - } - - /** - * Return the factory pid - * @return The factory pid or null. - */ - public String getFactoryPid() { - return this.factoryPid; - } - - /** - * Is this a special configuration? - * @return Special config - */ - public boolean isSpecial() { - if ( pid != null && pid.startsWith(":") ) { - return true; - } - return false; - } - - /** - * Get all properties of the configuration. - * @return The properties - */ - public Dictionary<String, Object> getProperties() { - return this.properties; - } - - @Override - public String toString() { - return "SSMConfiguration [pid=" + pid - + ", factoryPid=" + factoryPid - + ", properties=" + properties - + ( this.getLocation() != null ? ", location=" + this.getLocation() : "") - + "]"; - } -} diff --git a/src/main/java/org/apache/sling/slingstart/model/SSMConstants.java b/src/main/java/org/apache/sling/slingstart/model/SSMConstants.java deleted file mode 100644 index 064bb79..0000000 --- a/src/main/java/org/apache/sling/slingstart/model/SSMConstants.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package org.apache.sling.slingstart.model; - - -public abstract class SSMConstants { - - /** Name of the configuration containing the web.xml. */ - public static final String CFG_WEB_XML = ":web.xml"; - - /** Name of the configuration for the bootstrap contents. */ - public static final String CFG_BOOTSTRAP = ":bootstrap"; - - /** Unprocessed configuration values. */ - public static final String CFG_UNPROCESSED = ":rawconfig"; - - /** Format of the unprocessed configuration values. */ - public static final String CFG_UNPROCESSED_FORMAT = ":rawconfig.format"; - - public static final String CFG_FORMAT_FELIX_CA = "felixca"; - - public static final String CFG_FORMAT_PROPERTIES = "properties"; - - /** Name of the base run mode for the Sling launchpad. */ - public static final String RUN_MODE_BASE = ":base"; - - /** Name of the boot run mode. */ - public static final String RUN_MODE_BOOT = ":boot"; - - /** Name of the webapp run mode. */ - public static final String RUN_MODE_WEBAPP = ":webapp"; - - /** Name of the standalone run mode. */ - public static final String RUN_MODE_STANDALONE = ":standalone"; - -} diff --git a/src/main/java/org/apache/sling/slingstart/model/SSMDeliverable.java b/src/main/java/org/apache/sling/slingstart/model/SSMDeliverable.java deleted file mode 100644 index 472c40b..0000000 --- a/src/main/java/org/apache/sling/slingstart/model/SSMDeliverable.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package org.apache.sling.slingstart.model; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * A deliverable is the central object. - * It consists of a set of features and properties. - * The variables can be used for specifying artifact versions, referencing them - * with ${variableName} - * - * At least it has a "global" feature which contains artifacts that are always installed.. - */ -public class SSMDeliverable extends SSMTraceable { - - /** All features. */ - private final List<SSMFeature> features = new ArrayList<SSMFeature>(); - - /** Variables. */ - private final Map<String, String> variables = new HashMap<String, String>(); - - /** - * Construct a new deliverable. - */ - public SSMDeliverable() { - this.features.add(new SSMFeature(null)); // global features - } - - /** - * Find the feature if available - * @param runModes - * @return The feature or null. - */ - private SSMFeature findFeature(final String[] runModes) { - final String[] sortedRunModes = SSMFeature.getSortedRunModesArray(runModes); - SSMFeature result = null; - for(final SSMFeature current : this.features) { - if ( Arrays.equals(sortedRunModes, current.getRunModes()) ) { - result = current; - break; - } - } - return result; - } - - /** - * Get the feature if available - * @param runmode The single run mode. - * @return The feature or null - */ - public SSMFeature getRunMode(final String runMode) { - return findFeature(new String[] {runMode}); - } - - /** - * Get or create the feature. - * @param runModes The run modes. - * @return The feature for the given run modes. - */ - public SSMFeature getOrCreateFeature(final String[] runModes) { - SSMFeature result = findFeature(runModes); - if ( result == null ) { - result = new SSMFeature(runModes); - this.features.add(result); - Collections.sort(this.features); - } - return result; - } - - /** - * Return all features. - * The returned list is modifiable and directly modifies the model. - * @return The list of features. - */ - public List<SSMFeature> getFeatures() { - return this.features; - } - - /** - * Get all variables - * @return The set of variables - */ - public Map<String, String> getVariables() { - return this.variables; - } - - @Override - public String toString() { - return "SSMDeliverable [features=" + features - + ", variables=" + variables - + ( this.getLocation() != null ? ", location=" + this.getLocation() : "") - + "]"; - } -} diff --git a/src/main/java/org/apache/sling/slingstart/model/SSMFeature.java b/src/main/java/org/apache/sling/slingstart/model/SSMFeature.java deleted file mode 100644 index d81cd6c..0000000 --- a/src/main/java/org/apache/sling/slingstart/model/SSMFeature.java +++ /dev/null @@ -1,206 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package org.apache.sling.slingstart.model; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * A feature is a collection of - * - artifacts (through start levels) - * - configurations - * - settings - * - * A feature might be tied to run modes. Only if all run modes are active, - * this feature is active. - * In addition to custom, user defined run modes, special run modes exists. - * A special run mode name starts with a colon. - */ -public class SSMFeature - extends SSMTraceable - implements Comparable<SSMFeature> { - - private final String[] runModes; - - private final List<SSMStartLevel> startLevels = new ArrayList<SSMStartLevel>(); - - private final List<SSMConfiguration> configurations = new ArrayList<SSMConfiguration>(); - - private final Map<String, String> settings = new HashMap<String, String>(); - - public SSMFeature(final String[] runModes) { - this.runModes = getSortedRunModesArray(runModes); - } - - public static String[] getSortedRunModesArray(final String[] runModes) { - // sort run modes - if ( runModes != null ) { - final List<String> list = new ArrayList<String>(); - for(final String m : runModes) { - if ( m != null ) { - if ( !m.trim().isEmpty() ) { - list.add(m.trim()); - } - } - } - if ( list.size() > 0 ) { - Collections.sort(list); - return list.toArray(new String[list.size()]); - } - } - return null; - } - - public String[] getRunModes() { - return this.runModes; - } - - /** - * Check if this feature is active wrt the given set of active run modes. - */ - public boolean isActive(final Set<String> activeRunModes) { - boolean active = true; - if ( runModes != null ) { - for(final String mode : runModes) { - if ( !activeRunModes.contains(mode) ) { - active = false; - break; - } - } - } - return active; - } - - /** - * Check whether this feature is a special one - */ - public boolean isSpecial() { - if ( runModes != null && runModes.length == 1 && runModes[0].startsWith(":") ) { - return true; - } - return false; - } - - /** - * Check if this feature is tied to a single specific run mode. - */ - public boolean isRunMode(final String mode) { - if ( mode == null && this.runModes == null ) { - return true; - } - if ( mode != null - && this.runModes != null - && this.runModes.length == 1 - && this.runModes[0].equals(mode) ) { - return true; - } - return false; - } - - /** - * Get or create a start level - */ - public SSMStartLevel getOrCreateStartLevel(final int startLevel) { - for(final SSMStartLevel sl : this.startLevels) { - if ( sl.getLevel() == startLevel ) { - return sl; - } - } - final SSMStartLevel sl = new SSMStartLevel(startLevel); - this.startLevels.add(sl); - Collections.sort(this.startLevels); - return sl; - } - - /** - * Search a configuration with a pid - */ - public SSMConfiguration getConfiguration(final String pid) { - for(final SSMConfiguration c : this.configurations) { - if ( pid.equals(c.getPid()) ) { - return c; - } - } - return null; - } - - public SSMConfiguration getOrCreateConfiguration(final String pid, final String factoryPid) { - SSMConfiguration found = null; - for(final SSMConfiguration current : this.configurations) { - if ( factoryPid == null ) { - if ( current.getFactoryPid() == null && current.getPid().equals(pid) ) { - found = current; - break; - } - } else { - if ( factoryPid.equals(current.getFactoryPid()) && current.getPid().equals(pid) ) { - found = current; - break; - } - } - } - if ( found == null ) { - found = new SSMConfiguration(pid, factoryPid); - this.configurations.add(found); - } - return found; - } - - public List<SSMStartLevel> getStartLevels() { - return this.startLevels; - } - - public List<SSMConfiguration> getConfigurations() { - return this.configurations; - } - - public Map<String, String> getSettings() { - return this.settings; - } - - /** - * @see java.lang.Comparable#compareTo(java.lang.Object) - */ - @Override - public int compareTo( SSMFeature o2) { - if ( this.runModes == null ) { - if ( o2.runModes == null ) { - return 0; - } - return -1; - } - if ( o2.runModes == null ) { - return 1; - } - return Arrays.toString(this.runModes).compareTo(Arrays.toString(o2.runModes)); - } - - @Override - public String toString() { - return "SSMFeature [runModes=" + Arrays.toString(runModes) - + ", startLevels=" + startLevels - + ", configurations=" + configurations - + ", settings=" + settings - + ( this.getLocation() != null ? ", location=" + this.getLocation() : "") - + "]"; - } -} diff --git a/src/main/java/org/apache/sling/slingstart/model/SSMMerger.java b/src/main/java/org/apache/sling/slingstart/model/SSMMerger.java deleted file mode 100644 index 09e9ad8..0000000 --- a/src/main/java/org/apache/sling/slingstart/model/SSMMerger.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package org.apache.sling.slingstart.model; - -import java.util.Enumeration; - - -/** - * Merge two models - */ -public abstract class SSMMerger { - - /** - * Merge the additional model into the base model. - * @param base The base model. - * @param additional The additional model. - */ - public static void merge(final SSMDeliverable base, final SSMDeliverable additional) { - // features - for(final SSMFeature additionlFeature : additional.getFeatures()) { - final SSMFeature baseFeature = base.getOrCreateFeature(additionlFeature.getRunModes()); - - // start levels - for(final SSMStartLevel additionalStartLevel : additionlFeature.getStartLevels()) { - // search for duplicates in other start levels - for(final SSMArtifact artifact : additionalStartLevel.getArtifacts()) { - for(final SSMStartLevel mySL : baseFeature.getStartLevels()) { - if ( mySL.getLevel() == additionalStartLevel.getLevel() ) { - continue; - } - final SSMArtifact myArtifact = mySL.search(artifact); - if ( myArtifact != null ) { - mySL.getArtifacts().remove(myArtifact); - } - } - } - - // now merge current level - final SSMStartLevel baseStartLevel = baseFeature.getOrCreateStartLevel(additionalStartLevel.getLevel()); - - // artifacts - for(final SSMArtifact a : additionalStartLevel.getArtifacts()) { - final SSMArtifact found = baseStartLevel.search(a); - if ( found != null ) { - baseStartLevel.getArtifacts().remove(found); - } - baseStartLevel.getArtifacts().add(a); - } - } - - // configurations - for(final SSMConfiguration config : additionlFeature.getConfigurations()) { - final SSMConfiguration found = baseFeature.getOrCreateConfiguration(config.getPid(), config.getFactoryPid()); - final Enumeration<String> e = config.getProperties().keys(); - while ( e.hasMoreElements() ) { - final String key = e.nextElement(); - found.getProperties().put(key, config.getProperties().get(key)); - } - } - - // settings - baseFeature.getSettings().putAll(additionlFeature.getSettings()); - } - - // variables - base.getVariables().putAll(additional.getVariables()); - } -} diff --git a/src/main/java/org/apache/sling/slingstart/model/SSMStartLevel.java b/src/main/java/org/apache/sling/slingstart/model/SSMStartLevel.java deleted file mode 100644 index dbad45e..0000000 --- a/src/main/java/org/apache/sling/slingstart/model/SSMStartLevel.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package org.apache.sling.slingstart.model; - -import java.util.ArrayList; -import java.util.List; - -/** - * A start level holds a set of artifacts. - * A valid start level is positive, start level 0 means the default OSGi start level. - */ -public class SSMStartLevel extends SSMTraceable - implements Comparable<SSMStartLevel> { - - private final int level; - - private final List<SSMArtifact> artifacts = new ArrayList<SSMArtifact>(); - - public SSMStartLevel(final int level) { - this.level = level; - } - - public int getLevel() { - return this.level; - } - - public List<SSMArtifact> getArtifacts() { - return this.artifacts; - } - - /** - * Search an artifact with the same groupId, artifactId, version, type and classifier. - * Version is not considered. - */ - public SSMArtifact search(final SSMArtifact template) { - SSMArtifact found = null; - for(final SSMArtifact current : this.artifacts) { - if ( current.getGroupId().equals(template.getGroupId()) - && current.getArtifactId().equals(template.getArtifactId()) - && current.getClassifier().equals(template.getClassifier()) - && current.getType().equals(template.getType()) ) { - found = current; - break; - } - } - return found; - } - - @Override - public int compareTo(final SSMStartLevel o) { - if ( this.level < o.level ) { - return -1; - } else if ( this.level > o.level ) { - return 1; - } - return 0; - } - - @Override - public String toString() { - return "SSMStartLevel [level=" + level - + ", artifacts=" + artifacts - + ( this.getLocation() != null ? ", location=" + this.getLocation() : "") - + "]"; - } -} diff --git a/src/main/java/org/apache/sling/slingstart/model/SSMTraceable.java b/src/main/java/org/apache/sling/slingstart/model/SSMTraceable.java deleted file mode 100644 index 78be78c..0000000 --- a/src/main/java/org/apache/sling/slingstart/model/SSMTraceable.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package org.apache.sling.slingstart.model; - -public abstract class SSMTraceable { - - private String location; - - private String comment; - - public String getLocation() { - return this.location; - } - - public void setLocation(final String value) { - this.location = value; - } - - public String getComment() { - return this.comment; - } - - public void setComment(final String value) { - this.comment = value; - } - - @Override - public String toString() { - return "SSMTraceable [location=" + location + ", comment=" + comment - + "]"; - } -} - diff --git a/src/main/java/org/apache/sling/slingstart/model/SSMUtil.java b/src/main/java/org/apache/sling/slingstart/model/SSMUtil.java deleted file mode 100644 index a3c3b03..0000000 --- a/src/main/java/org/apache/sling/slingstart/model/SSMUtil.java +++ /dev/null @@ -1,194 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package org.apache.sling.slingstart.model; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.StringReader; -import java.util.Dictionary; -import java.util.Enumeration; -import java.util.Map; -import java.util.Properties; - -import org.apache.felix.cm.file.ConfigurationHandler; - -/** - * Utility methods - */ -public abstract class SSMUtil { - - /** - * Optional variable resolver - */ - public interface VariableResolver { - - /** - * Resolve the variable. - * An implementation might get the value of a variable from the system properties, - * or the environment etc. - * As a fallback, the resolver should check the variables of the model. - * @param model The model - * @param name The variable name - * @return The variable value or null. - */ - String resolve(final SSMDeliverable model, final String name); - } - - /** - * Replace all variables in the model and return a new model with the replaced values. - * @param model The base model. - * @param resolver Optional variable resolver. - * @return The model with replaced variables. - * @throws IllegalArgumentException If a variable can't be replaced or configuration properties can't be parsed - */ - public static SSMDeliverable getEffectiveModel(final SSMDeliverable model, final VariableResolver resolver) { - final SSMDeliverable result = new SSMDeliverable(); - result.setComment(model.getComment()); - result.setLocation(model.getLocation()); - result.getVariables().putAll(model.getVariables()); - - for(final SSMFeature feature : model.getFeatures()) { - final SSMFeature newFeature = result.getOrCreateFeature(feature.getRunModes()); - newFeature.setComment(feature.getComment()); - newFeature.setLocation(feature.getLocation()); - - for(final SSMStartLevel startLevel : feature.getStartLevels()) { - final SSMStartLevel newStartLevel = newFeature.getOrCreateStartLevel(startLevel.getLevel()); - newStartLevel.setComment(startLevel.getComment()); - newStartLevel.setLocation(startLevel.getLocation()); - - for(final SSMArtifact artifact : startLevel.getArtifacts()) { - final SSMArtifact newArtifact = new SSMArtifact(replace(model, artifact.getGroupId(), resolver), - replace(model, artifact.getArtifactId(), resolver), - replace(model, artifact.getVersion(), resolver), - replace(model, artifact.getClassifier(), resolver), - replace(model, artifact.getType(), resolver)); - newArtifact.setComment(artifact.getComment()); - newArtifact.setLocation(artifact.getLocation()); - - newStartLevel.getArtifacts().add(newArtifact); - } - } - - for(final SSMConfiguration config : feature.getConfigurations()) { - final SSMConfiguration newConfig = new SSMConfiguration(config.getPid(), config.getFactoryPid()); - newConfig.setComment(config.getComment()); - newConfig.setLocation(config.getLocation()); - - // check for raw configuration - final String rawConfig = (String)config.getProperties().get(SSMConstants.CFG_UNPROCESSED); - if ( rawConfig != null ) { - final String format = (String)config.getProperties().get(SSMConstants.CFG_UNPROCESSED_FORMAT); - - if ( SSMConstants.CFG_FORMAT_PROPERTIES.equals(format) ) { - // properties - final Properties props = new Properties(); - try { - props.load(new StringReader(rawConfig)); - } catch ( final IOException ioe) { - throw new IllegalArgumentException("Unable to read configuration properties.", ioe); - } - final Enumeration<Object> i = props.keys(); - while ( i.hasMoreElements() ) { - final String key = (String)i.nextElement(); - newConfig.getProperties().put(key, props.get(key)); - } - } else { - // Apache Felix CA format - ByteArrayInputStream bais = null; - try { - bais = new ByteArrayInputStream(rawConfig.getBytes("UTF-8")); - @SuppressWarnings("unchecked") - final Dictionary<String, Object> props = ConfigurationHandler.read(bais); - final Enumeration<String> i = props.keys(); - while ( i.hasMoreElements() ) { - final String key = i.nextElement(); - newConfig.getProperties().put(key, props.get(key)); - } - } catch ( final IOException ioe) { - throw new IllegalArgumentException("Unable to read configuration properties.", ioe); - } finally { - if ( bais != null ) { - try { - bais.close(); - } catch ( final IOException ignore ) { - // ignore - } - } - } - } - } else { - // simply copy - final Enumeration<String> i = config.getProperties().keys(); - while ( i.hasMoreElements() ) { - final String key = i.nextElement(); - newConfig.getProperties().put(key, config.getProperties().get(key)); - } - } - - newFeature.getConfigurations().add(newConfig); - } - - for(final Map.Entry<String, String> entry : feature.getSettings().entrySet() ) { - newFeature.getSettings().put(entry.getKey(), replace(model, entry.getValue(), resolver)); - } - } - return result; - } - - /** - * Replace properties in the string. - * - * @param model The model - * @param v The variable name - * @param resolver Optional resolver - * @result The value of the variable - * @throws IllegalArgumentException - */ - private static String replace(final SSMDeliverable model, final String v, final VariableResolver resolver) { - if ( v == null ) { - return null; - } - String msg = v; - // check for variables - int pos = -1; - int start = 0; - while ( ( pos = msg.indexOf('$', start) ) != -1 ) { - if ( msg.length() > pos && msg.charAt(pos + 1) == '{' && (pos == 0 || msg.charAt(pos - 1) != '$') ) { - final int endPos = msg.indexOf('}', pos); - if ( endPos == -1 ) { - start = pos + 1; - } else { - final String name = msg.substring(pos + 2, endPos); - final String value; - if ( resolver != null ) { - value = resolver.resolve(model, name); - } else { - value = model.getVariables().get(name); - } - if ( value == null ) { - throw new IllegalArgumentException("Unknown variable: " + name); - } - msg = msg.substring(0, pos) + value + msg.substring(endPos + 1); - } - } else { - start = pos + 1; - } - } - return msg; - } -} diff --git a/src/main/java/org/apache/sling/slingstart/model/SSMValidator.java b/src/main/java/org/apache/sling/slingstart/model/SSMValidator.java deleted file mode 100644 index b5ee003..0000000 --- a/src/main/java/org/apache/sling/slingstart/model/SSMValidator.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package org.apache.sling.slingstart.model; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; - -/** - * Validate a complete model. - */ -public abstract class SSMValidator { - - /** - * Validates the model. - * @param model - * @return - */ - public static Map<SSMTraceable, String> validate(final SSMDeliverable model) { - final Map<SSMTraceable, String> errors = new HashMap<SSMTraceable, String>(); - - for(final SSMFeature feature : model.getFeatures() ) { - final String[] rm = feature.getRunModes(); - if ( rm != null ) { - boolean hasSpecial = false; - for(final String m : rm) { - if ( m.startsWith(":") ) { - if ( hasSpecial ) { - errors.put(feature, "Invalid modes " + Arrays.toString(rm)); - break; - } - hasSpecial = true; - } - } - } - for(final SSMStartLevel sl : feature.getStartLevels()) { - if ( sl.getLevel() < 0 ) { - errors.put(sl, "Invalid start level " + sl.getLevel()); - } - for(final SSMArtifact a : sl.getArtifacts()) { - String error = null; - if ( a.getGroupId() == null || a.getGroupId().isEmpty() ) { - error = "groupId missing"; - } - if ( a.getArtifactId() == null || a.getArtifactId().isEmpty() ) { - error = (error != null ? error + ", " : "") + "artifactId missing"; - } - if ( a.getVersion() == null || a.getVersion().isEmpty() ) { - error = (error != null ? error + ", " : "") + "version missing"; - } - if ( a.getType() == null || a.getType().isEmpty() ) { - error = (error != null ? error + ", " : "") + "type missing"; - } - if (error != null) { - errors.put(a, error); - } - } - } - for(final SSMConfiguration c : feature.getConfigurations()) { - String error = null; - if ( c.getPid() == null || c.getPid().isEmpty() ) { - error = "pid missing"; - } - if ( c.isSpecial() && c.getFactoryPid() != null ) { - error = (error != null ? error + ", " : "") + "factory pid not allowed for special configuration"; - } - if ( c.getProperties().isEmpty() ) { - error = (error != null ? error + ", " : "") + "configuration properties missing"; - } - if (error != null) { - errors.put(c, error); - } - } - } - if ( errors.size() == 0 ) { - return null; - } - return errors; - } -} diff --git a/src/main/java/org/apache/sling/slingstart/model/package-info.java b/src/main/java/org/apache/sling/slingstart/model/package-info.java deleted file mode 100644 index fc31712..0000000 --- a/src/main/java/org/apache/sling/slingstart/model/package-info.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -@Version("1.0") -package org.apache.sling.slingstart.model; - -import aQute.bnd.annotation.Version; - diff --git a/src/main/java/org/apache/sling/slingstart/model/txt/TXTSSMModelReader.java b/src/main/java/org/apache/sling/slingstart/model/txt/TXTSSMModelReader.java deleted file mode 100644 index 2451d99..0000000 --- a/src/main/java/org/apache/sling/slingstart/model/txt/TXTSSMModelReader.java +++ /dev/null @@ -1,253 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.sling.slingstart.model.txt; - -import java.io.IOException; -import java.io.LineNumberReader; -import java.io.Reader; - -import org.apache.sling.slingstart.model.SSMArtifact; -import org.apache.sling.slingstart.model.SSMConfiguration; -import org.apache.sling.slingstart.model.SSMConstants; -import org.apache.sling.slingstart.model.SSMDeliverable; -import org.apache.sling.slingstart.model.SSMFeature; -import org.apache.sling.slingstart.model.SSMStartLevel; -import org.apache.sling.slingstart.model.SSMTraceable; - - -public class TXTSSMModelReader { - - public static final String FELIX_FORMAT_SUFFIX = "FORMAT:felix.config"; - - private enum MODE { - NONE, - VARS, - FEATURE, - START_LEVEL, - CONFIGURATION, - SETTINGS, - ARTIFACT - } - - /** - * Reads the deliverable file - * The reader is not closed. - * @throws IOException - */ - public static SSMDeliverable read(final Reader reader, final String location) - throws IOException { - final TXTSSMModelReader mr = new TXTSSMModelReader(location); - return mr.readModel(reader); - } - - private MODE mode = MODE.NONE; - - private final SSMDeliverable model = new SSMDeliverable(); - - private SSMFeature feature = null; - private SSMStartLevel startLevel = null; - private SSMConfiguration config = null; - private SSMArtifact artifact = null; - - private String comment = null; - - private StringBuilder configBuilder = null; - - private LineNumberReader lineNumberReader; - - private TXTSSMModelReader(final String location) { - this.model.setLocation(location); - } - - private SSMDeliverable readModel(final Reader reader) - throws IOException { - - boolean global = true; - - lineNumberReader = new LineNumberReader(reader); - String line; - while ( (line = lineNumberReader.readLine()) != null ) { - // ignore empty line - if ( line.trim().isEmpty() ) { - continue; - } - // comment? - if ( line.startsWith("#") ) { - checkConfig(); - mode = MODE.NONE; - final String c = line.substring(1).trim(); - if ( comment == null ) { - comment = c; - } else { - comment = comment + "\n" + c; - } - continue; - } - - if ( global ) { - global = false; - model.setComment(comment); - comment = null; - } - - final String trimmedLine = line.trim(); - final int pos = line.indexOf(':'); - final String params = (pos != -1 ? line.substring(pos + 1).trim() : null); - - if ( trimmedLine.startsWith("feature:") ) { - checkConfig(); - - mode = MODE.FEATURE; - feature = model.getOrCreateFeature(params.split(",")); - this.init(feature); - startLevel = feature.getOrCreateStartLevel(0); - - } else if ( trimmedLine.startsWith("variables:") ) { - checkConfig(); - - if ( comment != null ) { - throw new IOException("comment not allowed for variables in line " + this.lineNumberReader.getLineNumber()); - } - mode = MODE.VARS; - - } else if ( trimmedLine.startsWith("startLevel:") ) { - checkConfig(); - - if ( feature == null ) { - throw new IOException("startlevel outside of feature in line " + this.lineNumberReader.getLineNumber()); - } - int level = (params.length() == 0 ? level = 0 : Integer.valueOf(params)); - startLevel = feature.getOrCreateStartLevel(level); - this.init(startLevel); - mode = MODE.START_LEVEL; - - } else if ( trimmedLine.startsWith("config:") ) { - checkConfig(); - - if ( feature == null ) { - throw new IOException("configuration outside of feature in line " + this.lineNumberReader.getLineNumber()); - } - - String format = SSMConstants.CFG_FORMAT_FELIX_CA; - if ( trimmedLine.length() > 7 && !Character.isWhitespace(trimmedLine.charAt(7)) ) { - String formatDef = trimmedLine.substring(7); - if ( formatDef.equals(SSMConstants.CFG_FORMAT_PROPERTIES) || formatDef.startsWith(SSMConstants.CFG_FORMAT_PROPERTIES + " ")) { - format = SSMConstants.CFG_FORMAT_PROPERTIES; - } else if ( formatDef.equals(SSMConstants.CFG_FORMAT_FELIX_CA) || formatDef.startsWith(SSMConstants.CFG_FORMAT_FELIX_CA + " ")) { - format = SSMConstants.CFG_FORMAT_FELIX_CA; - } else { - throw new IOException("Unknown configuration format: " + formatDef + " in line " + this.lineNumberReader.getLineNumber()); - } - } - final int factoryPos = params.indexOf('-'); - if ( factoryPos == -1 ) { - config = new SSMConfiguration(params, null); - } else { - config = new SSMConfiguration(params.substring(pos + 1), params.substring(0, pos)); - } - this.init(config); - config.getProperties().put(SSMConstants.CFG_UNPROCESSED_FORMAT, format); - feature.getConfigurations().add(config); - configBuilder = new StringBuilder(); - mode = MODE.CONFIGURATION; - - } else if ( trimmedLine.startsWith("settings:") ) { - checkConfig(); - - if ( comment != null ) { - throw new IOException("comment not allowed for settings in line " + this.lineNumberReader.getLineNumber()); - } - if ( startLevel == null ) { - throw new IOException("settings outside of feature/startlevel in line " + this.lineNumberReader.getLineNumber()); - } - mode = MODE.SETTINGS; - - } else if ( trimmedLine.startsWith("artifact:") ) { - checkConfig(); - - if ( startLevel == null ) { - throw new IOException("artifact outside of feature/startlevel in line " + this.lineNumberReader.getLineNumber()); - } - - mode = MODE.ARTIFACT; - try { - artifact = SSMArtifact.fromMvnUrl("mvn:" + params); - } catch ( final IllegalArgumentException iae) { - throw new IOException(iae.getMessage() + " in line " + this.lineNumberReader.getLineNumber(), iae); - } - this.init(artifact); - startLevel.getArtifacts().add(artifact); - - } else { - switch ( mode ) { - case NONE: throw new IOException("No global contents allowed in line " + this.lineNumberReader.getLineNumber()); - case ARTIFACT : final String[] metadata = parseProperty(trimmedLine); - artifact.getMetadata().put(metadata[0], metadata[1]); - break; - case VARS : final String[] vars = parseProperty(trimmedLine); - model.getVariables().put(vars[0], vars[1]); - break; - case SETTINGS : final String[] settings = parseProperty(trimmedLine); - feature.getSettings().put(settings[0], settings[1]); - break; - case FEATURE: throw new IOException("No contents allowed for feature in line " + this.lineNumberReader.getLineNumber()); - case START_LEVEL: throw new IOException("No contents allowed for feature in line " + this.lineNumberReader.getLineNumber()); - case CONFIGURATION: configBuilder.append(trimmedLine); - configBuilder.append('\n'); - break; - } - } - } - checkConfig(); - if ( comment != null ) { - throw new IOException("Comment not allowed at the end of file"); - } - - return model; - } - - private void init(final SSMTraceable traceable) { - traceable.setComment(this.comment); - this.comment = null; - final String number = String.valueOf(this.lineNumberReader.getLineNumber()); - if ( model.getLocation() != null ) { - traceable.setLocation(model.getLocation() + ":" + number); - } else { - traceable.setLocation(number); - } - } - - private void checkConfig() { - if ( config != null ) { - config.getProperties().put(SSMConstants.CFG_UNPROCESSED, configBuilder.toString()); - } - config = null; - configBuilder = null; - } - - private String[] parseProperty(final String line) throws IOException { - final int equalsPos = line.indexOf('='); - final String key = line.substring(0, equalsPos).trim(); - final String value = line.substring(equalsPos + 1).trim(); - if (key.isEmpty() || value.isEmpty() ) { - throw new IOException("Invalid property; " + line + " in line " + this.lineNumberReader.getLineNumber()); - } - return new String[] {key, value}; - } -} - - diff --git a/src/main/java/org/apache/sling/slingstart/model/txt/TXTSSMModelWriter.java b/src/main/java/org/apache/sling/slingstart/model/txt/TXTSSMModelWriter.java deleted file mode 100644 index 12534c5..0000000 --- a/src/main/java/org/apache/sling/slingstart/model/txt/TXTSSMModelWriter.java +++ /dev/null @@ -1,203 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package org.apache.sling.slingstart.model.txt; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.LineNumberReader; -import java.io.PrintWriter; -import java.io.StringReader; -import java.io.Writer; -import java.util.Map; - -import org.apache.felix.cm.file.ConfigurationHandler; -import org.apache.sling.slingstart.model.SSMArtifact; -import org.apache.sling.slingstart.model.SSMConfiguration; -import org.apache.sling.slingstart.model.SSMConstants; -import org.apache.sling.slingstart.model.SSMDeliverable; -import org.apache.sling.slingstart.model.SSMFeature; -import org.apache.sling.slingstart.model.SSMStartLevel; -import org.apache.sling.slingstart.model.SSMTraceable; - -/** - * Simple writer for the a model - */ -public class TXTSSMModelWriter { - - private static void writeComment(final PrintWriter pw, final SSMTraceable traceable) - throws IOException { - if ( traceable.getComment() != null ) { - final LineNumberReader lnr = new LineNumberReader(new StringReader(traceable.getComment())); - try { - String line = null; - while ( (line = lnr.readLine()) != null ) { - pw.print("# "); - pw.println(line); - } - } finally { - lnr.close(); - } - } - } - - /** - * Writes the model to the writer. - * The writer is not closed. - * @param writer - * @param subystem - * @throws IOException - */ - public static void write(final Writer writer, final SSMDeliverable model) - throws IOException { - final PrintWriter pw = new PrintWriter(writer); - - writeComment(pw, model); - // variables - if ( model.getVariables().size() > 0 ) { - pw.println("variables:"); - for(final Map.Entry<String, String> entry : model.getVariables().entrySet()) { - pw.print(" "); - pw.print(entry.getKey()); - pw.print("="); - pw.println(entry.getValue()); - } - pw.println(); - } - - // features - for(final SSMFeature feature : model.getFeatures()) { - // skip empty feature - if ( feature.getConfigurations().isEmpty() && feature.getSettings().isEmpty() ) { - boolean hasArtifacts = false; - for(final SSMStartLevel sl : feature.getStartLevels()) { - if ( !sl.getArtifacts().isEmpty() ) { - hasArtifacts = true; - break; - } - } - if ( !hasArtifacts ) { - continue; - } - } - writeComment(pw, feature); - pw.print("feature:"); - final String[] runModes = feature.getRunModes(); - if ( runModes != null && runModes.length > 0 ) { - pw.print(" "); - boolean first = true; - for(final String mode : runModes) { - if ( first ) { - first = false; - } else { - pw.print(","); - } - pw.print(mode); - } - } - pw.println(); - - // settings - if ( feature.getSettings().size() > 0 ) { - pw.println(" settings:"); - - for(final Map.Entry<String, String> entry :feature.getSettings().entrySet()) { - pw.print(" "); - pw.print(entry.getKey()); - pw.print("="); - pw.println(entry.getValue()); - } - pw.println(); - } - - // start level - for(final SSMStartLevel startLevel : feature.getStartLevels()) { - // skip empty levels - if ( startLevel.getArtifacts().size() == 0 ) { - continue; - } - writeComment(pw, startLevel); - pw.print(" startLevel: "); - pw.print(String.valueOf(startLevel.getLevel())); - pw.println(); - pw.println(); - - // artifacts - for(final SSMArtifact ad : startLevel.getArtifacts()) { - writeComment(pw, ad); - pw.print(" "); - pw.print("artifact: "); - pw.print(ad.toMvnUrl().substring(4)); - pw.println(); - if ( ad.getMetadata().size() > 0 ) { - for(final Map.Entry<String, String> entry : ad.getMetadata().entrySet()) { - pw.print(" "); - pw.print(entry.getKey()); - pw.print("="); - pw.println(entry.getValue()); - } - } - } - if ( startLevel.getArtifacts().size() > 0 ) { - pw.println(); - } - } - - // configurations - for(final SSMConfiguration config : feature.getConfigurations()) { - writeComment(pw, config); - final String raw = (String)config.getProperties().get(SSMConstants.CFG_UNPROCESSED); - String format = (String)config.getProperties().get(SSMConstants.CFG_UNPROCESSED_FORMAT); - if ( format == null ) { - format = SSMConstants.CFG_FORMAT_FELIX_CA; - } - pw.print(" config:"); - if ( !SSMConstants.CFG_FORMAT_FELIX_CA.equals(format) ) { - pw.print(format); - } - pw.print(" "); - if ( config.getFactoryPid() != null ) { - pw.print(config.getFactoryPid()); - pw.print("-"); - } - pw.print(config.getPid()); - pw.println(); - final String configString; - if ( raw != null ) { - configString = raw; - } else if ( config.isSpecial() ) { - configString = config.getProperties().get(config.getPid()).toString(); - } else { - final ByteArrayOutputStream os = new ByteArrayOutputStream(); - try { - ConfigurationHandler.write(os , config.getProperties()); - } finally { - os.close(); - } - configString = new String(os.toByteArray(), "UTF-8"); - } - // we have to read the configuration line by line to properly indent - final LineNumberReader lnr = new LineNumberReader(new StringReader(configString)); - String line = null; - while ((line = lnr.readLine()) != null ) { - pw.print(" "); - pw.println(line); - } - pw.println(); - } - } - } -} diff --git a/src/main/java/org/apache/sling/slingstart/model/txt/package-info.java b/src/main/java/org/apache/sling/slingstart/model/txt/package-info.java deleted file mode 100644 index 5a2902a..0000000 --- a/src/main/java/org/apache/sling/slingstart/model/txt/package-info.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -@Version("1.0") -package org.apache.sling.slingstart.model.txt; - -import aQute.bnd.annotation.Version; - -- To stop receiving notification emails like this one, please contact "commits@sling.apache.org" <commits@sling.apache.org>.