पर अपडेट करने के बाद काम नहीं करता है मैंने एक ग्रहण प्लगइन बनाया है जो गोल्ज क्लोजर कंपाइलर के साथ एक मिनीस्क्रिप्ट जावास्क्रिप्ट फ़ाइल बनाने के लिए सहेजने की क्रिया में हुक करेगा। नीचे फाइलें देखें। जो ग्रहण 3.7.2 तक काम करता था। दुर्भाग्यवश अब ग्रहण 4.2.1 में ऐसा लगता है कि यह कभी-कभी अंतहीन पाश बनाता है। नौकरी "compile .min.js" (ResourceChangedListener.java में पंक्ति 64) कारण है। इसके परिणामस्वरूप कार्यस्थल का निर्माण शुरू हो जाता है। मुझे लगता है कि ऐसा इसलिए है क्योंकि वह कार्य वर्कस्पेस को फिर से बनाने वाली फ़ाइल को बनाता या बदलता है, जो फिर से उस काम को ट्रिगर करता है जो निर्माण को ट्रिगर करता है और इसी तरह। लेकिन मैं यह नहीं समझ सकता कि इसे कैसे रोकें।ग्रहण प्लगइन जूनो (ग्रहण 4)
// Activator.java
package closure_compiler_save;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
/**
* The activator class controls the plug-in life cycle
*/
public class Activator extends AbstractUIPlugin {
// The plug-in ID
public static final String PLUGIN_ID = "closure-compiler-save"; //$NON-NLS-1$
// The shared instance
private static Activator plugin;
/**
* The constructor
*/
public Activator() {
}
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
Activator.plugin = this;
ResourceChangedListener listener = new ResourceChangedListener();
ResourcesPlugin.getWorkspace().addResourceChangeListener(listener);
}
@Override
public void stop(BundleContext context) throws Exception {
Activator.plugin = null;
super.stop(context);
}
/**
* Returns the shared instance
*
* @return the shared instance
*/
public static Activator getDefault() {
return plugin;
}
}
// ResourceChangedListener.java
package closure_compiler_save;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
public class ResourceChangedListener implements IResourceChangeListener {
public void resourceChanged(IResourceChangeEvent event) {
if (event.getType() != IResourceChangeEvent.POST_CHANGE)
return;
IResourceDelta delta = event.getDelta();
try {
processDelta(delta);
} catch (CoreException e) {
e.printStackTrace();
}
}
// find out which class files were just built
private void processDelta(IResourceDelta delta) throws CoreException {
IResourceDelta[] kids = delta.getAffectedChildren();
for (IResourceDelta delta2 : kids) {
if (delta2.getAffectedChildren().length == 0) {
if (delta.getKind() != IResourceDelta.CHANGED)
return;
IResource res = delta2.getResource();
if (res.getType() == IResource.FILE && "js".equalsIgnoreCase(res.getFileExtension())) {
if (res.getName().contains("min"))
return;
compile(res);
}
}
processDelta(delta2);
}
}
private void compile(final IResource res) throws CoreException {
final IPath fullPath = res.getFullPath();
final IPath fullLocation = res.getLocation();
final String fileName = fullPath.lastSegment().toString();
final String outputFilename = fileName.substring(0, fileName.lastIndexOf(".")).concat(".min.js");
final String outputPath = fullPath.removeFirstSegments(1).removeLastSegments(1).toString();
final IProject project = res.getProject();
final IFile newFile = project.getFile(outputPath.concat("/".concat(outputFilename)));
Job compileJob = new Job("Compile .min.js") {
public IStatus run(IProgressMonitor monitor) {
byte[] bytes = null;
try {
bytes = CallCompiler.compile(fullLocation.toString(), CallCompiler.SIMPLE_OPTIMIZATION).getBytes();
InputStream source = new ByteArrayInputStream(bytes);
if (!newFile.exists()) {
newFile.create(source, IResource.NONE, null);
} else {
newFile.setContents(source, IResource.NONE, null);
}
} catch (IOException e) {
e.printStackTrace();
} catch (CoreException e) {
e.printStackTrace();
}
return Status.OK_STATUS;
}
};
compileJob.setRule(newFile.getProject()); // this will ensure that no two jobs are writing simultaneously on the same file
compileJob.schedule();
}
}
कॉलकंपलर कहां से आता है? क्या यह एक तृतीय पक्ष जार से है जिसे आपने अपने ग्रहण प्लगइन फ़ोल्डर में शायद एक/lib dir में शामिल किया है? यदि आपने किया है, तो सुनिश्चित करें कि तृतीय पक्ष जार Manifest.mf रनटाइम पथ (manifest.mf संपादक में संपादित) पर है और यह भी सुनिश्चित करें कि bin.includs में build.properties पर इसमें तीसरे पक्ष की जार शामिल होगी । – gamerson
CallCompiler मेरी अपनी कक्षा है, यह फ़ाइल में प्रश्न के लिए क्लोजर कंपाइलर को कॉल करता है। उस वर्ग में तर्क काम करता है। मेरे पास एक पॉपअप मेनू भी है जो एक ही कॉलकंपेलर क्लास वाली फ़ाइल के लिए minify प्रक्रिया को ट्रिगर करता है। बस स्वचालित बचत प्रक्रिया अब काम नहीं करेगी। – DarsVaeda
अजीब, तो यह आपके वर्कस्पेस/रनटाइम वर्कबेंच में काम करता है लेकिन स्टैंडअलोन इंस्टॉल नहीं करता है। मैंने कई बार देखा है। कोड को देखते हुए, res.getLocation() कॉल से सावधान रहें। मैंने देखा है कि कुछ स्थितियों में वापसी शून्य है। मेरा एकमात्र सुझाव अब यह देखने के लिए है कि dev संस्करण और स्थापित संस्करण के बीच अंतर क्या है, यह देखने के लिए अपनी संकलन() विधि के लिए अधिक डीबग आउटपुट जोड़ना है। – gamerson