001    /*
002     *  Licensed under the Apache License, Version 2.0 (the "License");
003     *  you may not use this file except in compliance with the License.
004     *  You may obtain a copy of the License at
005     *
006     *      http://www.apache.org/licenses/LICENSE-2.0
007     *
008     *  Unless required by applicable law or agreed to in writing, software
009     *  distributed under the License is distributed on an "AS IS" BASIS,
010     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
011     *  See the License for the specific language governing permissions and
012     *  limitations under the License.
013     */
014    /*
015     * This file has been modified by Chris Pheby in accordance with Section 4.2
016     * of the Apache Software License
017     */
018    package org.jadira.dependencynavigator.implementations;
019    
020    import org.apache.maven.model.Model;
021    import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
022    import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
023    import org.jadira.dependencynavigator.assembler.Assembler;
024    import org.jadira.dependencynavigator.assembler.AssemblerException;
025    import org.jadira.dependencynavigator.controller.DependencyResolutionException;
026    import org.jadira.dependencynavigator.model.Artifact;
027    import org.jadira.dependencynavigator.model.ArtifactInitialisationException;
028    import org.jadira.dependencynavigator.model.PomFile;
029    import org.jadira.dependencynavigator.model.RootPom;
030    
031    import java.io.BufferedReader;
032    import java.io.FileNotFoundException;
033    import java.io.IOException;
034    
035    public abstract class Workspace {
036    
037        public static final String ROLE = "org.jadira.dependencynavigator.implementations.Workspace";
038        /**
039         * the root of the pom hierarachy. this will be an entity in the workspace
040         */
041        protected RootPom root;
042    
043        private Assembler assembler;
044    
045        private Repository repository;
046    
047        public abstract PomFile loadModulePom(String module);
048    
049        public abstract String getPath(String moduleName);
050    
051        public abstract void reloadPomFile() throws ArtifactInitialisationException;
052    
053        public abstract boolean canCreateSnapshot();
054    
055        public RootPom getRoot() {
056            return this.root;
057        }
058    
059        protected PomFile loadPom(BufferedReader pomFile) {
060            try {
061                MavenXpp3Reader pomReader = new MavenXpp3Reader();
062                Model model = pomReader.read(new BufferedReader(pomFile));
063                return new PomFile(assembler.assemble(model, repository), null, Artifact.DEFAULT_SCOPE);
064            } catch (FileNotFoundException e) {
065                throw new DependencyResolutionException(e);
066            } catch (IOException e) {
067                throw new DependencyResolutionException(e);
068            } catch (XmlPullParserException e) {
069                throw new DependencyResolutionException(e);
070            } catch (ArtifactInitialisationException e) {
071                throw new DependencyResolutionException(e);
072            } catch (AssemblerException e) {
073                throw new DependencyResolutionException(e);
074            }
075        }
076    }