Java 类org.apache.maven.model.InputLocation 实例源码

项目:incubator-netbeans    文件:ModelUtils.java   
/**
 * Opens a pom file at location defined in InputLocation parameter
 * @since 2.77
 * @param location 
 */
public static void openAtSource(InputLocation location) {
    InputSource source = location.getSource();
    if (source != null && source.getLocation() != null) {
        FileObject fobj = FileUtilities.convertStringToFileObject(source.getLocation());
        if (fobj != null) {
            try {
                DataObject dobj = DataObject.find(NodeUtils.readOnlyLocalRepositoryFile(fobj));
                EditCookie edit = dobj.getLookup().lookup(EditCookie.class);
                if (edit != null) {
                    edit.edit();
                }
                LineCookie lc = dobj.getLookup().lookup(LineCookie.class);
                lc.getLineSet().getOriginal(location.getLineNumber() - 1).show(Line.ShowOpenType.REUSE, Line.ShowVisibilityType.FOCUS, location.getColumnNumber() - 1);
            } catch (DataObjectNotFoundException ex) {
                LOG.log(Level.FINE, "dataobject not found", ex);
            }
        }
    }
}
项目:incubator-netbeans    文件:AnnotationBar.java   
@NbBundle.Messages("ACT_GoToSource=Go to Source")
private JPopupMenu createPopup(MouseEvent e) {
    final JPopupMenu popupMenu = new JPopupMenu();

    // annotation for target line
    if (elementAnnotations != null) {
        final Location al = getAnnotateLine(getLineFromMouseEvent(e));
        if (al != null) {
            JMenuItem item = new JMenuItem(ACT_GoToSource());
            popupMenu.add(item);
            item.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent ae) {
                    InputLocation loc = al.loc;
                    if (loc != null) {
                        ModelUtils.openAtSource(loc);
                    }
                }
            });
        }
    }
    return popupMenu;
}
项目:incubator-netbeans    文件:HyperlinkProviderImpl.java   
public static void openAtSource(InputLocation location) {
    InputSource source = location.getSource();
    if (source != null && source.getLocation() != null) {
        FileObject fobj = FileUtilities.convertStringToFileObject(source.getLocation());
        if (fobj != null) {
            try {
                DataObject dobj = DataObject.find(NodeUtils.readOnlyLocalRepositoryFile(fobj));
                EditCookie edit = dobj.getLookup().lookup(EditCookie.class);
                if (edit != null) {
                    edit.edit();
                }
                LineCookie lc = dobj.getLookup().lookup(LineCookie.class);
                lc.getLineSet().getOriginal(location.getLineNumber() - 1).show(Line.ShowOpenType.REUSE, Line.ShowVisibilityType.FOCUS, location.getColumnNumber() - 1);
            } catch (DataObjectNotFoundException ex) {
                LOG.log(Level.FINE, "dataobject not found", ex);
            }
        }
    }
}
项目:incubator-netbeans    文件:NBModelBuilder.java   
@Override
public ModelBuildingResult build(ModelBuildingRequest request) throws ModelBuildingException {
    ModelBuildingResult toRet = super.build(request);
    Model eff = toRet.getEffectiveModel();
    InputSource source = new InputSource();
    source.setLocation("");
    InputLocation location = new InputLocation(-1, -1, source);
    eff.setLocation(NETBEANS_PROFILES, location);
    for (String id : toRet.getModelIds()) {
        Model mdl = toRet.getRawModel(id);
        for (Profile p : mdl.getProfiles()) {
            source.setLocation(source.getLocation() + "|" + p.getId());
        }
    }
    return toRet;
}
项目:oceano    文件:ModelMerger.java   
protected void mergeModelBase_Properties( ModelBase target, ModelBase source, boolean sourceDominant,
                                          Map<Object, Object> context )
{
    Properties merged = new Properties();
    if ( sourceDominant )
    {
        merged.putAll( target.getProperties() );
        merged.putAll( source.getProperties() );
    }
    else
    {
        merged.putAll( source.getProperties() );
        merged.putAll( target.getProperties() );
    }
    target.setProperties( merged );
    target.setLocation( "properties", InputLocation.merge( target.getLocation( "properties" ),
                                                           source.getLocation( "properties" ), sourceDominant ) );
}
项目:oceano    文件:ModelMerger.java   
protected void mergeContributor_Properties( Contributor target, Contributor source, boolean sourceDominant,
                                            Map<Object, Object> context )
{
    Properties merged = new Properties();
    if ( sourceDominant )
    {
        merged.putAll( target.getProperties() );
        merged.putAll( source.getProperties() );
    }
    else
    {
        merged.putAll( source.getProperties() );
        merged.putAll( target.getProperties() );
    }
    target.setProperties( merged );
    target.setLocation( "properties", InputLocation.merge( target.getLocation( "properties" ),
                                                           source.getLocation( "properties" ), sourceDominant ) );
}
项目:oceano    文件:StringSearchModelInterpolatorTest.java   
public void testLocationTrackerShouldBeExcludedFromInterpolation()
{
    Properties props = new Properties();
    props.setProperty( "expression", "value" );
    DefaultModelBuildingRequest request = new DefaultModelBuildingRequest();
    request.setUserProperties( props );

    InputSource source = new InputSource();
    source.setLocation( "${expression}" );
    source.setModelId( "${expression}" );
    Model model = new Model();
    model.setLocation( "", new InputLocation( 1, 1, source ) );

    SimpleProblemCollector problems = new SimpleProblemCollector();
    StringSearchModelInterpolator interpolator = new StringSearchModelInterpolator();
    interpolator.interpolateObject( model, model, null, request, problems );

    assertProblemFree( problems );
    assertEquals( "${expression}", source.getLocation() );
    assertEquals( "${expression}", source.getModelId() );
}
项目:incubator-netbeans    文件:LocationAwareMavenXpp3Writer.java   
private void logLocation(InputLocationTracker tracker, Object value, int startOffset, int endOffset) {
    if (tracker != null) {
        InputLocation loc = tracker.getLocation(value);
        if (loc != null) {
            locations.add(new Location(loc, startOffset, endOffset));
        }
    }
}
项目:incubator-netbeans    文件:LocationAwareMavenXpp3Writer.java   
private void writeMailingList(MailingList mailingList, String tagName, XmlSerializer serializer)
        throws java.io.IOException {
    serializer.startTag(NAMESPACE, tagName);
    flush(serializer);
    StringBuffer b = b(serializer);
    int start = b.length();

    if (mailingList.getName() != null) {
        writeValue(serializer, "name", mailingList.getName(), mailingList);
    }
    if (mailingList.getSubscribe() != null) {
        writeValue(serializer, "subscribe", mailingList.getSubscribe(), mailingList);
    }
    if (mailingList.getUnsubscribe() != null) {
        writeValue(serializer, "unsubscribe", mailingList.getUnsubscribe(), mailingList);
    }
    if (mailingList.getPost() != null) {
        writeValue(serializer, "post", mailingList.getPost(), mailingList);
    }
    if (mailingList.getArchive() != null) {
        writeValue(serializer, "archive", mailingList.getArchive(), mailingList);
    }
    if ((mailingList.getOtherArchives() != null) && (mailingList.getOtherArchives().size() > 0)) {
        serializer.startTag(NAMESPACE, "otherArchives");
        flush(serializer);
        InputLocation otherLoc = mailingList.getLocation("otherArchives");
        int index = 0;
        for (Iterator iter = mailingList.getOtherArchives().iterator(); iter.hasNext();) {
            String otherArchive = (String) iter.next();
            writeValue(serializer, "otherArchive", otherArchive, otherLoc, index);
            index = index + 1;
        }
        serializer.endTag(NAMESPACE, "otherArchives");
    }
    serializer.endTag(NAMESPACE, tagName).flush();
    logLocation(mailingList, "", start, b.length());

}
项目:incubator-netbeans    文件:LocationAwareMavenXpp3Writer.java   
private void writePluginExecution(PluginExecution pluginExecution, String tagName, XmlSerializer serializer)
        throws java.io.IOException {
    serializer.startTag(NAMESPACE, tagName);
    flush(serializer);
    StringBuffer b = b(serializer);
    int start = b.length();
    if ((pluginExecution.getId() != null) && !pluginExecution.getId().equals("default")) {
        writeValue(serializer, "id", pluginExecution.getId(), pluginExecution);
    }
    if (pluginExecution.getPhase() != null) {
        writeValue(serializer, "phase", pluginExecution.getPhase(), pluginExecution);
    }
    if ((pluginExecution.getGoals() != null) && (pluginExecution.getGoals().size() > 0)) {
        serializer.startTag(NAMESPACE, "goals");
        flush(serializer);
        int start2 = b.length();
        int index = 0;
        InputLocation tracker = pluginExecution.getLocation("goals");

        for (Iterator iter = pluginExecution.getGoals().iterator(); iter.hasNext();) {
            String goal = (String) iter.next();
            writeValue(serializer, "goal", goal, tracker, index);
            index = index + 1;
        }
        serializer.endTag(NAMESPACE, "goals").flush();
        logLocation(pluginExecution, "goals", start2, b.length());
    }
    if (pluginExecution.getInherited() != null) {
        writeValue(serializer, "inherited", pluginExecution.getInherited(), pluginExecution);
    }
    if (pluginExecution.getConfiguration() != null) {
        writeXpp3DOM(serializer, (Xpp3Dom)pluginExecution.getConfiguration(), pluginExecution);
    }
    serializer.endTag(NAMESPACE, tagName).flush();
    logLocation(pluginExecution, "", start, b.length());
}
项目:incubator-netbeans    文件:LocationAwareMavenXpp3Writer.java   
private void writeReportSet(ReportSet reportSet, String tagName, XmlSerializer serializer)
        throws java.io.IOException {
    serializer.startTag(NAMESPACE, tagName);
    flush(serializer);
    StringBuffer b = b(serializer);
    int start = b.length();
    if ((reportSet.getId() != null) && !reportSet.getId().equals("default")) {
        writeValue(serializer, "id", reportSet.getId(), reportSet);
    }
    if ((reportSet.getReports() != null) && (reportSet.getReports().size() > 0)) {
        serializer.startTag(NAMESPACE, "reports");
        flush(serializer);
        int start2 = b.length();
        InputLocation tracker = reportSet.getLocation("reports");
        int index = 0;
        for (Iterator iter = reportSet.getReports().iterator(); iter.hasNext();) {
            String report = (String) iter.next();
            writeValue(serializer, "report", report, tracker, index);
            index = index + 1;
        }
        serializer.endTag(NAMESPACE, "reports").flush();
        logLocation(reportSet, "reports", start2, b.length());
    }
    if (reportSet.getInherited() != null) {
        writeValue(serializer, "inherited", reportSet.getInherited(), reportSet);
    }
    if (reportSet.getConfiguration() != null) {
        writeXpp3DOM(serializer, (Xpp3Dom)reportSet.getConfiguration(), reportSet);
    }
    serializer.endTag(NAMESPACE, tagName).flush();
    logLocation(reportSet, "", start, b.length());
}
项目:incubator-netbeans    文件:NBModelBuilder.java   
public static Set<String> getAllProfiles(Model mdl) {
    InputLocation location = mdl.getLocation(NETBEANS_PROFILES);
    HashSet<String> toRet = new HashSet<String>();
    if (location != null) {
        String s = location.getSource().getLocation();
        if (!s.isEmpty()) {
            s = s.substring(1);
            toRet.addAll(Arrays.asList(s.split("\\|")));
        }
        return toRet;
    }
    return null;
}
项目:incubator-netbeans    文件:NBModelBuilder.java   
/**
 *
 * @param effective model created by Project Maven Embedder.
 * @return 
 */
public static List<ModelDescription> getModelDescriptors(Model effective) {
    InputLocation loc = effective.getLocation(NETBEANS_MODELDESCS);
    if (loc != null && loc.getSource() instanceof ModelInputSource) {
        ModelInputSource mis = (ModelInputSource) loc.getSource();
        return mis.rawModels;
    }
    return null;
}
项目:xmvn    文件:BuilddepMojo.java   
private Set<Artifact> getModelDependencies( Model model )
{
    Function<InputLocation, Boolean> isExternalLocation =
        location -> !reactorProjects.stream() //
                                    .map( project -> project.getModel().getLocation( "" ).getSource().getModelId() ) //
                                    .filter( modelId -> modelId.equals( location.getSource().getModelId() ) ) //
                                    .findAny().isPresent();
    BuildDependencyVisitor visitor = new BuildDependencyVisitor( isExternalLocation );
    modelProcessor.processModel( model.clone(), visitor );
    return visitor.getArtifacts();
}
项目:oceano    文件:DefaultProjectDependenciesResolver.java   
private void appendManagementSource( StringBuilder buffer, org.sonatype.aether.artifact.Artifact artifact,
                                     String field )
{
    if ( managed == null )
    {
        managed = new HashMap<String, Dependency>();
        if ( project.getDependencyManagement() != null )
        {
            for ( Dependency dep : project.getDependencyManagement().getDependencies() )
            {
                managed.put( dep.getManagementKey(), dep );
            }
        }
    }

    String key =
        ArtifacIdUtils.toVersionlessId( artifact.getGroupId(), artifact.getArtifactId(),
                                        artifact.getProperty( ArtifactProperties.TYPE, "jar" ),
                                        artifact.getClassifier() );

    Dependency dependency = managed.get( key );
    if ( dependency != null )
    {
        InputLocation location = dependency.getLocation( field );
        if ( location != null )
        {
            InputSource source = location.getSource();
            if ( source != null )
            {
                buffer.append( " by " ).append( source.getModelId() );
            }
        }
    }
}
项目:oceano    文件:MavenModelMerger.java   
@Override
protected void mergeModelBase_Modules( ModelBase target, ModelBase source, boolean sourceDominant,
                                       Map<Object, Object> context )
{
    List<String> src = source.getModules();
    if ( !src.isEmpty() && sourceDominant )
    {
        List<Integer> indices = new ArrayList<Integer>();
        List<String> tgt = target.getModules();
        Set<String> excludes = new LinkedHashSet<String>( tgt );
        List<String> merged = new ArrayList<String>( tgt.size() + src.size() );
        merged.addAll( tgt );
        for ( int i = 0, n = tgt.size(); i < n; i++ )
        {
            indices.add( Integer.valueOf( i ) );
        }
        for ( int i = 0, n = src.size(); i < n; i++ )
        {
            String s = src.get( i );
            if ( !excludes.contains( s ) )
            {
                merged.add( s );
                indices.add( Integer.valueOf( ~i ) );
            }
        }
        target.setModules( merged );
        target.setLocation( "modules", InputLocation.merge( target.getLocation( "modules" ),
                                                            source.getLocation( "modules" ), indices ) );
    }
}
项目:incubator-netbeans    文件:ExecMojo.java   
public InputLocation getLocation() {
    return location;
}
项目:incubator-netbeans    文件:ExecMojo.java   
private void setLocation(InputLocation location) {
    this.location = location;
}
项目:incubator-netbeans    文件:LocationAwareMavenXpp3Writer.java   
public Location(InputLocation loc, int startOffset, int endOffset) {
    this.loc = loc;
    this.startOffset = startOffset;
    this.endOffset = endOffset;
}
项目:xmvn    文件:BuildDependencyVisitor.java   
public BuildDependencyVisitor( Function<InputLocation, Boolean> isExternalLocation )
{
    this.isExternalLocation = isExternalLocation;
}
项目:xmvn    文件:BuildDependencyVisitor.java   
private boolean isExternal( InputLocation location )
{
    return location == null || isExternalLocation.apply( location );
}
项目:diet-maven-mojo    文件:MavenMinimizerMojo.java   
private Minimizer buildUpDependenciesLegacy(Minimizer minimizer) throws IOException {

        // set up list of classes to force include (e.g. runtime dependencies)
        if (forceInclude != null) {
            List<ClassName> classNames = new ArrayList<ClassName>();
            for (String classToForceInclude : forceInclude) {
                classNames.add(new ClassName(classToForceInclude));
            }

            minimizer.forceInclude(classNames.toArray(new ClassName[classNames.size()]));
        }

        // set up Maven project dependencies
        // Set<Artifact> artifacts = project.getDependencyArtifacts(); // FIXME transitive dependencies NOT included
        DependencyManagement dependancyManagenment = project.getDependencyManagement();

        Set<File> artifactLocations = new HashSet<File>();
        for (Dependency dependency : dependancyManagenment.getDependencies()) {
            // we want to exclude test or provided artifacts - the first because
            // they will never be required in the final assembly of the
            // minimized application, the second because they are already
            // provided and we might introduce conflicts
            if (Artifact.SCOPE_TEST.equals(dependency.getScope())
                    || Artifact.SCOPE_PROVIDED.equals(dependency.getScope())) {
                getLog().debug("Excluding test or provided artifact : " + dependency.getArtifactId());
            } else {
                InputLocation location = dependancyManagenment.getLocation(dependency);
                artifactLocations.add(new File(location.getSource().getLocation()));
            }
        }

        // if inspecting the Maven project resulted in an empty list then we
        // fallback to the Maven project local repository (could be very costly
        // as this directory typically contains lots of files)
        if (artifactLocations.isEmpty()) {
            getLog().warn("Could not get list of dependencies from Maven, reverting to Maven local repository");
            return minimizer.libs(pathToLocalRepo);
        }

        return minimizer.libs(artifactLocations);
    }
项目:oceano    文件:DefaultModelValidator.java   
private static InputLocation getLocation( String fieldName, InputLocationTracker tracker )
{
    InputLocation location = null;

    if ( tracker != null )
    {
        if ( fieldName != null )
        {
            Object key = fieldName;

            int idx = fieldName.lastIndexOf( '.' );
            if ( idx >= 0 )
            {
                fieldName = fieldName.substring( idx + 1 );
                key = fieldName;
            }

            if ( fieldName.endsWith( "]" ) )
            {
                key = fieldName.substring( fieldName.lastIndexOf( '[' ) + 1, fieldName.length() - 1 );
                try
                {
                    key = Integer.valueOf( key.toString() );
                }
                catch ( NumberFormatException e )
                {
                    // use key as is
                }
            }

            location = tracker.getLocation( key );
        }

        if ( location == null )
        {
            location = tracker.getLocation( "" );
        }
    }

    return location;
}
项目:oceano    文件:ModelProblemCollectorRequest.java   
public InputLocation getLocation()
{
    return location;
}
项目:oceano    文件:ModelProblemCollectorRequest.java   
public ModelProblemCollectorRequest setLocation(InputLocation location)
{
    this.location = location;
    return this;
}