github.com/adnan-c/fabric_e2e_couchdb@v0.6.1-preview.0.20170228180935-21ce6b23cf91/core/chaincode/platforms/java/package.go (about)

     1  /*
     2  Copyright DTCC 2016 All Rights Reserved.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8           http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package java
    18  
    19  import (
    20  	"archive/tar"
    21  	"fmt"
    22  	"strings"
    23  
    24  	"os"
    25  
    26  	"errors"
    27  
    28  	cutil "github.com/hyperledger/fabric/core/container/util"
    29  	pb "github.com/hyperledger/fabric/protos/peer"
    30  )
    31  
    32  //tw is expected to have the chaincode in it from GenerateHashcode.
    33  //This method will just package the dockerfile
    34  func writeChaincodePackage(spec *pb.ChaincodeSpec, tw *tar.Writer) error {
    35  
    36  	var urlLocation string
    37  	var err error
    38  
    39  	if strings.HasPrefix(spec.ChaincodeId.Path, "http://") ||
    40  		strings.HasPrefix(spec.ChaincodeId.Path, "https://") {
    41  
    42  		urlLocation, err = getCodeFromHTTP(spec.ChaincodeId.Path)
    43  		defer func() {
    44  			os.RemoveAll(urlLocation)
    45  		}()
    46  		if err != nil {
    47  			return err
    48  		}
    49  	} else {
    50  		urlLocation = spec.ChaincodeId.Path
    51  	}
    52  
    53  	if urlLocation == "" {
    54  		return errors.New("ChaincodeSpec's path/URL cannot be empty")
    55  	}
    56  
    57  	if strings.LastIndex(urlLocation, "/") == len(urlLocation)-1 {
    58  		urlLocation = urlLocation[:len(urlLocation)-1]
    59  	}
    60  
    61  	err = cutil.WriteJavaProjectToPackage(tw, urlLocation)
    62  	if err != nil {
    63  		return fmt.Errorf("Error writing Chaincode package contents: %s", err)
    64  	}
    65  
    66  	return nil
    67  }