1.1 --- a/dew4nb/nbproject/project.xml Tue Feb 11 18:05:20 2014 +0100
1.2 +++ b/dew4nb/nbproject/project.xml Wed Feb 12 19:44:33 2014 +0100
1.3 @@ -116,7 +116,7 @@
1.4 <build-prerequisite/>
1.5 <compile-dependency/>
1.6 <run-dependency>
1.7 - <specification-version>0.134</specification-version>
1.8 + <implementation-version/>
1.9 </run-dependency>
1.10 </dependency>
1.11 <dependency>
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/dew4nb/src/org/netbeans/modules/dew4nb/RemoteSourceFileObject.java Wed Feb 12 19:44:33 2014 +0100
2.3 @@ -0,0 +1,124 @@
2.4 +/*
2.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2.6 + *
2.7 + * Copyright 2014 Oracle and/or its affiliates. All rights reserved.
2.8 + *
2.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
2.10 + * Other names may be trademarks of their respective owners.
2.11 + *
2.12 + * The contents of this file are subject to the terms of either the GNU
2.13 + * General Public License Version 2 only ("GPL") or the Common
2.14 + * Development and Distribution License("CDDL") (collectively, the
2.15 + * "License"). You may not use this file except in compliance with the
2.16 + * License. You can obtain a copy of the License at
2.17 + * http://www.netbeans.org/cddl-gplv2.html
2.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
2.19 + * specific language governing permissions and limitations under the
2.20 + * License. When distributing the software, include this License Header
2.21 + * Notice in each file and include the License file at
2.22 + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
2.23 + * particular file as subject to the "Classpath" exception as provided
2.24 + * by Oracle in the GPL Version 2 section of the License file that
2.25 + * accompanied this code. If applicable, add the following below the
2.26 + * License Header, with the fields enclosed by brackets [] replaced by
2.27 + * your own identifying information:
2.28 + * "Portions Copyrighted [year] [name of copyright owner]"
2.29 + *
2.30 + * If you wish your version of this file to be governed by only the CDDL
2.31 + * or only the GPL Version 2, indicate your decision by adding
2.32 + * "[Contributor] elects to include this software in this distribution
2.33 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
2.34 + * single choice of license, a recipient has the option to distribute
2.35 + * your version of this file under either the CDDL, the GPL Version 2 or
2.36 + * to extend the choice of license to its licensees as provided above.
2.37 + * However, if you add GPL Version 2 code and therefore, elected the GPL
2.38 + * Version 2 license, then the option applies only if the new code is
2.39 + * made subject to such option by the copyright holder.
2.40 + *
2.41 + * Contributor(s):
2.42 + *
2.43 + * Portions Copyrighted 2014 Sun Microsystems, Inc.
2.44 + */
2.45 +
2.46 +package org.netbeans.modules.dew4nb;
2.47 +
2.48 +import java.io.FileNotFoundException;
2.49 +import java.io.IOException;
2.50 +import java.io.OutputStream;
2.51 +import org.netbeans.api.annotations.common.CheckForNull;
2.52 +import org.netbeans.api.annotations.common.NonNull;
2.53 +import org.netbeans.api.annotations.common.NullAllowed;
2.54 +import org.netbeans.modules.java.preprocessorbridge.spi.JavaFileFilterImplementation;
2.55 +import org.netbeans.modules.java.source.parsing.AbstractSourceFileObject;
2.56 +import org.netbeans.modules.parsing.api.Source;
2.57 +import org.openide.filesystems.FileObject;
2.58 +import org.openide.filesystems.FileUtil;
2.59 +
2.60 +/**
2.61 + *
2.62 + * @author Tomas Zezula
2.63 + */
2.64 +final class RemoteSourceFileObject extends AbstractSourceFileObject {
2.65 +
2.66 + private final boolean hasFilter;
2.67 +
2.68 + RemoteSourceFileObject(
2.69 + @NonNull final AbstractSourceFileObject.Handle handle,
2.70 + @NullAllowed final JavaFileFilterImplementation filter,
2.71 + @NullAllowed final CharSequence content,
2.72 + final boolean renderNow) throws IOException {
2.73 + super(handle, filter);
2.74 + if (content != null) {
2.75 + update(content);
2.76 + } else if (renderNow) {
2.77 + update();
2.78 + }
2.79 + hasFilter = filter != null;
2.80 + }
2.81 +
2.82 + @Override
2.83 + @CheckForNull
2.84 + protected Long isDirty() {
2.85 + return getRemoteContent() != null ?
2.86 + System.currentTimeMillis() :
2.87 + null;
2.88 + }
2.89 +
2.90 + @Override
2.91 + @CheckForNull
2.92 + protected OutputStream createOutputStream() throws IOException {
2.93 + //Todo: sync to remote
2.94 + return null;
2.95 + }
2.96 +
2.97 + @Override
2.98 + @NonNull
2.99 + protected CharSequence createContent() throws IOException {
2.100 + CharSequence content = getRemoteContent();
2.101 + if (content == null) {
2.102 + final FileObject file = getHandle().resolveFileObject(false);
2.103 + if (file == null) {
2.104 + throw new FileNotFoundException("Cannot open file: " + toString());
2.105 + }
2.106 + final Source source = Source.create(file);
2.107 + if (source == null) {
2.108 + throw new IOException("No source for: " + FileUtil.getFileDisplayName(file)); //NOI18N
2.109 + }
2.110 + content = source.createSnapshot().getText();
2.111 + if (hasFilter && source.getDocument(false) == null) {
2.112 + content = filter(content);
2.113 + }
2.114 + }
2.115 + return content;
2.116 + }
2.117 +
2.118 +
2.119 + @CheckForNull
2.120 + private CharSequence getRemoteContent() {
2.121 + final FileObject file = getHandle().resolveFileObject(false);
2.122 + return file == null ?
2.123 + null :
2.124 + SourceProvider.getInstance().getContentFor(file);
2.125 + }
2.126 +
2.127 +}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/dew4nb/src/org/netbeans/modules/dew4nb/RemoteSourceFileProvider.java Wed Feb 12 19:44:33 2014 +0100
3.3 @@ -0,0 +1,70 @@
3.4 +/*
3.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3.6 + *
3.7 + * Copyright 2014 Oracle and/or its affiliates. All rights reserved.
3.8 + *
3.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
3.10 + * Other names may be trademarks of their respective owners.
3.11 + *
3.12 + * The contents of this file are subject to the terms of either the GNU
3.13 + * General Public License Version 2 only ("GPL") or the Common
3.14 + * Development and Distribution License("CDDL") (collectively, the
3.15 + * "License"). You may not use this file except in compliance with the
3.16 + * License. You can obtain a copy of the License at
3.17 + * http://www.netbeans.org/cddl-gplv2.html
3.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
3.19 + * specific language governing permissions and limitations under the
3.20 + * License. When distributing the software, include this License Header
3.21 + * Notice in each file and include the License file at
3.22 + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
3.23 + * particular file as subject to the "Classpath" exception as provided
3.24 + * by Oracle in the GPL Version 2 section of the License file that
3.25 + * accompanied this code. If applicable, add the following below the
3.26 + * License Header, with the fields enclosed by brackets [] replaced by
3.27 + * your own identifying information:
3.28 + * "Portions Copyrighted [year] [name of copyright owner]"
3.29 + *
3.30 + * If you wish your version of this file to be governed by only the CDDL
3.31 + * or only the GPL Version 2, indicate your decision by adding
3.32 + * "[Contributor] elects to include this software in this distribution
3.33 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
3.34 + * single choice of license, a recipient has the option to distribute
3.35 + * your version of this file under either the CDDL, the GPL Version 2 or
3.36 + * to extend the choice of license to its licensees as provided above.
3.37 + * However, if you add GPL Version 2 code and therefore, elected the GPL
3.38 + * Version 2 license, then the option applies only if the new code is
3.39 + * made subject to such option by the copyright holder.
3.40 + *
3.41 + * Contributor(s):
3.42 + *
3.43 + * Portions Copyrighted 2014 Sun Microsystems, Inc.
3.44 + */
3.45 +
3.46 +package org.netbeans.modules.dew4nb;
3.47 +
3.48 +import java.io.IOException;
3.49 +import org.netbeans.api.annotations.common.NonNull;
3.50 +import org.netbeans.api.annotations.common.NullAllowed;
3.51 +import org.netbeans.modules.java.preprocessorbridge.spi.JavaFileFilterImplementation;
3.52 +import org.netbeans.modules.java.source.parsing.AbstractSourceFileObject;
3.53 +import org.netbeans.modules.java.source.parsing.SourceFileObjectProvider;
3.54 +import org.openide.util.lookup.ServiceProvider;
3.55 +
3.56 +/**
3.57 + *
3.58 + * @author Tomas Zezula
3.59 + */
3.60 +@ServiceProvider(service = SourceFileObjectProvider.class)
3.61 +public final class RemoteSourceFileProvider implements SourceFileObjectProvider {
3.62 +
3.63 + @Override
3.64 + @NonNull
3.65 + public AbstractSourceFileObject createJavaFileObject(
3.66 + @NonNull final AbstractSourceFileObject.Handle handle,
3.67 + @NullAllowed final JavaFileFilterImplementation filter,
3.68 + @NullAllowed final CharSequence content,
3.69 + final boolean renderNow) throws IOException {
3.70 + //Todo: content = null, renderNow = false now
3.71 + return new RemoteSourceFileObject(handle, filter, null, false);
3.72 + }
3.73 +}
4.1 --- a/dew4nb/src/org/netbeans/modules/dew4nb/SourceProvider.java Tue Feb 11 18:05:20 2014 +0100
4.2 +++ b/dew4nb/src/org/netbeans/modules/dew4nb/SourceProvider.java Wed Feb 12 19:44:33 2014 +0100
4.3 @@ -50,26 +50,26 @@
4.4 import java.lang.ref.SoftReference;
4.5 import java.lang.ref.WeakReference;
4.6 import java.util.Collections;
4.7 +import java.util.EnumSet;
4.8 +import java.util.HashMap;
4.9 import java.util.LinkedHashMap;
4.10 import java.util.Map;
4.11 import java.util.logging.Level;
4.12 import java.util.logging.Logger;
4.13 -import javax.swing.text.BadLocationException;
4.14 -import javax.swing.text.Document;
4.15 -import javax.swing.text.StyledDocument;
4.16 import org.netbeans.api.annotations.common.CheckForNull;
4.17 import org.netbeans.api.annotations.common.NonNull;
4.18 import org.netbeans.api.annotations.common.NullAllowed;
4.19 import org.netbeans.modules.dew4nb.spi.WorkspaceResolver;
4.20 import org.netbeans.modules.parsing.api.Source;
4.21 -import org.openide.cookies.EditorCookie;
4.22 +import org.netbeans.modules.parsing.impl.SourceAccessor;
4.23 +import org.netbeans.modules.parsing.impl.SourceFlags;
4.24 +import org.openide.filesystems.FileChangeAdapter;
4.25 +import org.openide.filesystems.FileChangeListener;
4.26 +import org.openide.filesystems.FileEvent;
4.27 import org.openide.filesystems.FileLock;
4.28 import org.openide.filesystems.FileObject;
4.29 import org.openide.filesystems.FileSystem;
4.30 import org.openide.filesystems.FileUtil;
4.31 -import org.openide.loaders.DataObject;
4.32 -import org.openide.loaders.DataObjectNotFoundException;
4.33 -import org.openide.text.NbDocument;
4.34 import org.openide.util.Exceptions;
4.35 import org.openide.util.Parameters;
4.36 import org.openide.util.Utilities;
4.37 @@ -118,6 +118,11 @@
4.38 }
4.39 }
4.40 });
4.41 + //@GuardedBy("modifiedContent")
4.42 + private final Map<FileObject, CharSequence> modifiedContent
4.43 + = Collections.synchronizedMap(new HashMap<FileObject, CharSequence>());
4.44 +
4.45 + private final FileChangeListener fileListener = new RepoFileListener();
4.46
4.47
4.48 private SourceProvider() {
4.49 @@ -168,6 +173,11 @@
4.50 }
4.51
4.52 @CheckForNull
4.53 + CharSequence getContentFor(@NonNull final FileObject file) {
4.54 + return modifiedContent.get(file);
4.55 + }
4.56 +
4.57 + @CheckForNull
4.58 private FileObject createTempFile(String content) {
4.59 FileObject file = null;
4.60 if (content != null) {
4.61 @@ -204,41 +214,30 @@
4.62 if (tmpFile) {
4.63 return;
4.64 }
4.65 - if (content == null) {
4.66 - try {
4.67 - final DataObject dobj = DataObject.find(source.getFileObject());
4.68 - final EditorCookie ec = dobj.getLookup().lookup(EditorCookie.class);
4.69 - if (ec != null) {
4.70 - final Document doc = ec.getDocument();
4.71 - if (doc != null) {
4.72 - ec.close();
4.73 - }
4.74 + final FileObject file = source.getFileObject();
4.75 + boolean dirty = false;
4.76 + if (content == null) {
4.77 + modifiedContent.remove(file);
4.78 + dirty = true;
4.79 + } else {
4.80 + synchronized(modifiedContent) {
4.81 + final CharSequence origContent = modifiedContent.get(file);
4.82 + if (origContent == null) {
4.83 + file.addFileChangeListener(fileListener);
4.84 + dirty = true;
4.85 + } else if (!content.contentEquals(origContent)) {
4.86 + dirty = true;
4.87 }
4.88 - } catch (DataObjectNotFoundException nfe) {
4.89 - LOG.log(
4.90 - Level.INFO,
4.91 - "Cannot find DataObject: {0}", //NOI18N
4.92 - FileUtil.getFileDisplayName(source.getFileObject()));
4.93 + if (dirty) {
4.94 + modifiedContent.put(file, content);
4.95 + }
4.96 }
4.97 -
4.98 - } else {
4.99 - final Document doc = source.getDocument(true);
4.100 - NbDocument.runAtomic(
4.101 - (StyledDocument)doc,
4.102 - new Runnable() {
4.103 - @Override
4.104 - public void run() {
4.105 - try {
4.106 - final String docContent = doc.getText(0, doc.getLength());
4.107 - if (!content.equals(docContent)) {
4.108 - doc.remove(0, doc.getLength());
4.109 - doc.insertString(0, content, null);
4.110 - }
4.111 - } catch (BadLocationException ble) {
4.112 - throw new IllegalStateException(ble);
4.113 - }
4.114 - }
4.115 - });
4.116 + }
4.117 + if (dirty) {
4.118 + LOG.log(Level.FINE, "Dirty file: {0}", file); //NOI18N
4.119 + SourceAccessor.getINSTANCE().setFlags(
4.120 + source,
4.121 + EnumSet.of(SourceFlags.INVALID));
4.122 }
4.123 }
4.124
4.125 @@ -346,4 +345,31 @@
4.126 active.remove(this.file);
4.127 }
4.128 }
4.129 +
4.130 + private class RepoFileListener extends FileChangeAdapter {
4.131 +
4.132 + @Override
4.133 + public void fileChanged(FileEvent fe) {
4.134 + handleChange(fe.getFile());
4.135 + }
4.136 +
4.137 + @Override
4.138 + public void fileDeleted(FileEvent fe) {
4.139 + handleChange(fe.getFile());
4.140 + }
4.141 +
4.142 + @Override
4.143 + public void fileDataCreated(FileEvent fe) {
4.144 + handleChange(fe.getFile());
4.145 + }
4.146 +
4.147 + private void handleChange (FileObject file) {
4.148 + LOG.log(Level.FINE, "Clean file: {0}", file); //NOI18N
4.149 + synchronized (modifiedContent) {
4.150 + if (modifiedContent.remove(file) != null) {
4.151 + file.removeFileChangeListener(fileListener);
4.152 + }
4.153 + }
4.154 + }
4.155 + }
4.156 }