KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > correction > AddSourceBuildEntryResolution


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.ui.correction;
12
13 import java.util.ArrayList JavaDoc;
14
15 import org.eclipse.core.resources.IMarker;
16 import org.eclipse.core.resources.IProject;
17 import org.eclipse.core.runtime.CoreException;
18 import org.eclipse.jdt.core.IClasspathEntry;
19 import org.eclipse.jdt.core.IJavaProject;
20 import org.eclipse.jdt.core.JavaCore;
21 import org.eclipse.jdt.core.JavaModelException;
22 import org.eclipse.osgi.util.NLS;
23 import org.eclipse.pde.core.build.IBuildEntry;
24 import org.eclipse.pde.internal.build.IBuildPropertiesConstants;
25 import org.eclipse.pde.internal.core.builders.BuildErrorReporter;
26 import org.eclipse.pde.internal.core.text.build.Build;
27 import org.eclipse.pde.internal.core.text.build.BuildEntry;
28 import org.eclipse.pde.internal.ui.PDEUIMessages;
29
30 public class AddSourceBuildEntryResolution extends BuildEntryMarkerResolution {
31
32     public AddSourceBuildEntryResolution(int type, IMarker marker) {
33         super(type, marker);
34     }
35
36     public String JavaDoc getLabel() {
37         return NLS.bind(PDEUIMessages.AddSourceBuildEntryResolution_label, fEntry);
38     }
39     
40     protected void createChange(Build build) {
41         try {
42             BuildEntry buildEntry = (BuildEntry)build.getEntry(fEntry);
43             boolean unlistedOnly = true;
44             if (buildEntry == null) {
45                 buildEntry = new BuildEntry(fEntry, build.getModel());
46                 unlistedOnly = false;
47             }
48             String JavaDoc[] unlisted = getSourcePaths(build, unlistedOnly);
49             for (int i = 0; i < unlisted.length; i++) {
50                 if (unlisted[i] == null)
51                     break;
52                 buildEntry.addToken(unlisted[i]);
53             }
54         } catch (CoreException e) {
55         }
56     }
57
58     private String JavaDoc[] getSourcePaths(Build build, boolean unlistedOnly) {
59         IProject project = build.getModel().getUnderlyingResource().getProject();
60         try {
61             if (project.hasNature(JavaCore.NATURE_ID)) {
62                 ArrayList JavaDoc sourceEntries = new ArrayList JavaDoc();
63                 IBuildEntry[] entries = build.getBuildEntries();
64                 if (unlistedOnly)
65                     for (int i = 0; i < entries.length; i++)
66                         if (entries[i].getName().startsWith(IBuildPropertiesConstants.PROPERTY_SOURCE_PREFIX))
67                             sourceEntries.add(entries[i]);
68                 
69                 IJavaProject jp = JavaCore.create(project);
70                 IClasspathEntry[] cpes = jp.getRawClasspath();
71                 return BuildErrorReporter.getUnlistedClasspaths(sourceEntries, project, cpes);
72             }
73         } catch (JavaModelException e) {
74         } catch (CoreException e) {
75         }
76         return null;
77     }
78 }
79
Popular Tags